Solved! Go to solution

How to insert a Block Occurrence

[ Edited ]

Does anyone have some sample code showing how to insert a block occurrence into a draft file?  This includes positioning the block and setting its scale.



Accepted by topic author breving
‎08-26-2015 04:32 AM

Re: How to insert a Block Occurrence

Ok. I got it.  It comes down to understanding the difference between a block and a block occurrence.  Basically, you add a block to a new drawing by using the CopyBlock command on a block from a different drawing.  Then you Add an occurrence of that block to the sheet that you want.


 objDocBlocks = objApp.Documents.Open("C:\existing_blocks.dft")
Dim objBlocks As SolidEdgeDraft.Blocks = objDocBlocks.Blocks
Dim objBlock0 As SolidEdgeDraft.Block = objBlocks.Item(0)

objDocNew = objApp.Documents.Open("C:\temp\new_blocks.dft")
Dim objBlocksNew As SolidEdgeDraft.Blocks = objDocNew.Blocks
Dim objBlockNew0 As SolidEdgeDraft.Block = objBlocksNew.CopyBlock(objBlock0)

Dim objSheet1 As SolidEdgeDraft.Sheet = objDocNew.ActiveSheet
Dim objBlockOccurencesNew As SolidEdgeDraft.BlockOccurrences = objSheet1.BlockOccurrences

objBlockOccurencesNew.Add(objBlockNew0.Name, 0.05, 0.01, Scale:=0.00125)