Message 1 of 3

Not applicable
07-01-2019
04:11 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I want to get a block with attributes to my drawings, but the code makes some trouble.
If I run the script for the 1st time, it works, but if I delete the block and purge Blocks from the drawing, so the drawing seems to be new, I get an error, when I rerun the script: calling method SetObjectId of interface |Acadbaseobject failed
I can't use the code twice in a file (if the block is deleted & purged), but I can't find an error.
Last week I typed the whole code to a new dvb-file (character by character) and it worked many times?
Today I opened my file, and again - it only worked once.
Can anybody give me a tipp or advice what's wrong?
The Code:
Sub Create_Block_w_Attribute() ' Define the block Dim blockObj As AcadBlock Dim insertionPnt(0 To 2) As Double insertionPnt(0) = 0 insertionPnt(1) = 0 insertionPnt(2) = 0 Set blockObj = ThisDrawing.Blocks.Add(insertionPnt, "T-X-RE") ' Add attributes to the block Dim attributeObj As AcadAttribute Dim height As Double Dim mode As Long Dim prompt1 As String Dim prompt2 As String Dim prompt3 As String Dim prompt4 As String Dim insertionPoint1(0 To 2) As Double Dim insertionPoint2(0 To 2) As Double Dim insertionPoint3(0 To 2) As Double Dim insertionPoint4(0 To 2) As Double Dim tag1 As String Dim tag2 As String Dim tag3 As String Dim tag4 As String Dim value As String height = 3.5 mode = acAttributeModeVerify prompt1 = "X" prompt2 = "Y" prompt3 = "Z" prompt4 = "Weight" insertionPoint1(0) = 30.5: insertionPoint1(1) = 29: insertionPoint1(2) = 0 insertionPoint2(0) = 30.5: insertionPoint2(1) = 21.5: insertionPoint2(2) = 0 insertionPoint3(0) = 30.5: insertionPoint3(1) = 14: insertionPoint3(2) = 0 insertionPoint4(0) = 30.5: insertionPoint4(1) = 4: insertionPoint4(2) = 0 tag1 = "T-X" tag2 = "T-Y" tag3 = "T-Z" tag4 = "T-Weight" value = "0.000" Set attributeObj = blockObj.AddAttribute(height, mode, prompt1, insertionPoint1, tag1, value) Set attributeObj = blockObj.AddAttribute(height, mode, prompt2, insertionPoint2, tag2, value) Set attributeObj = blockObj.AddAttribute(height, mode, prompt3, insertionPoint3, tag3, value) Set attributeObj = blockObj.AddAttribute(height, mode, prompt4, insertionPoint4, tag4, value) ' Insert the block, creating a block reference and an attribute reference Dim blockRefObj As AcadBlockReference insertionPnt(0) = 0 insertionPnt(1) = 0 insertionPnt(2) = 0 Set blockRefObj = ThisDrawing.ModelSpace.InsertBlock(insertionPnt, "T-X-RE", 1#, 1#, 1#, 0) End Sub
Thanks and kind regards
Solved! Go to Solution.