I have back ground sheets of all different sized title blocks. I created all of them to include a common block, so I could update them all quickly. I can copy a new block into a draft with api, and I can replace a block occurance by hand, but I can't find a way to replace the block with a changed block using api. Has anyone had a similar need?
I have a macro that changes one block occurrence by another different block occurrence.
I use it to change surface finishing symbols.
Once you have copied the modified block to the draft file you have to:
Delete the old occurrences (objsheet is the sheet where you have the block occurence):
Try For Each blockitem In objSheet.BlockOccurrences Dim blockname As String = blockitem.Block.Name If blockname = "your block name" Then
blockitem.GetOrigin(X, Y) ' To get the origin of the occurrence blockitem.delete() End If Next Catch ex As Exception End Try
Add the new ones in the desired position (here we insert the new block in the same position where the old block was).
newblock = objDraftDoc.Blocks.Item("your modified block")
objSheet.BlockOccurrences.Add(newblock.Name, X, Y)
Hope it heps.
Héctor Pelayo Izquierdo
Engineering Department, JAE Ingeniería y Desarrollos, S.L.
Solid Edge ST9 MP5 | NX 9
I was hoping to not need to delete and place a differeny block, but that seems to be the only option for now. I have submitted a PR for the ability to replace with API, since the ability is there with the GUI.
Thanks for your help!
the block that is being deleted is clear ... but if the new block isn't in the drafting where from will it be added and how does the macro know that ?