Click here to Skip to main content
15,886,963 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All,

Good day to all.
Appreciate if someone could assist me on this error code. The error is Method 'OwnerID' of object 'IAcadBlock' failed.
Been trying google this error but nothing prevail.
When I debug it, the error point to this line.
Appreciate help on this matter


SQL
' Create the attribute definition object on the block
    Set CompAtt = blockObj.AddAttribute(HeightComp, ModeComp, PromptComp, insertionPnt, TagComp, ValueComp)
    Set CompAtt = blockObj.AddAttribute(HeightComp, ModeComp, PromptComp, insertionPnt, "Quantity", "1")


Here is my complete coding.
Private Sub CommandButton2_Click()
Dim StartPoint As Variant
Dim SP1, SP2, BP1, BP2 As Double
Dim ValWidth, ValHeight As Double
Dim ValWGap, ValHGap, ValMGap, ValFDGap As Double
Dim BPHeight, BPWidth, FrameDepth, ClearEntry As Double

frmDrawComp.Hide

StartPoint = ThisDrawing.Utility.GetPoint(, "Enter Start point: ")
   
SP1 = StartPoint(0)
SP2 = StartPoint(1)
   
Dim PROFILE, BlockName As String
PROFILE = cbListIL.value
FrameDepth = txtFrameDepth.Text
ClearEntry = txtClearEntry.Text
'BASEPLATE = cbListBP.Value
BlockName = PROFILE & ClearEntry & FrameDepth


Select Case PROFILE
Case "S18"
ValWidth = 87.6
ValHeight = 61.6
ValMGap = 45.2
ValWGap = (ValWidth - ValMGap) / 2
ValHGap = ValHeight / 2
ValBracing = 22
ValBraceGap = (ValMGap - ValBracing) / 2

Case "M20"
ValWidth = 88#
ValHeight = 61.7
ValMGap = 45.2
ValWGap = (ValWidth - ValMGap) / 2
ValHGap = ValHeight / 2
ValBracing = 22
ValBraceGap = (ValMGap - ValBracing) / 2

End Select

 ValFDGap = FrameDepth - (ValHeight + ValHeight)
 
 'Define the block
 Dim blockObj As AcadBlock
 Dim insertionPnt(0 To 2) As Double
 insertionPnt(0) = SP1
 insertionPnt(1) = SP2
 insertionPnt(2) = 0
 Set blockObj = ThisDrawing.Blocks.Add(insertionPnt, BlockName)

 Dim plineObj As AcadPolyline
 Dim CompA(0 To 23) As Double

 'Define Upright polyline CompA
 CompA(0) = SP1 + ValWGap: CompA(1) = SP2 + ValHeight: CompA(2) = 0
 CompA(3) = SP1 + ValWGap: CompA(4) = SP2 + ValHGap: CompA(5) = 0
 CompA(6) = SP1: CompA(7) = SP2 + ValHGap: CompA(8) = 0
 CompA(9) = SP1: CompA(10) = SP2: CompA(11) = 0
 CompA(12) = SP1 + ValWidth: CompA(13) = SP2: CompA(14) = 0
 CompA(15) = SP1 + ValWidth: CompA(16) = SP2 + ValHGap: CompA(17) = 0
 CompA(18) = (SP1 + ValWidth) - ValWGap: CompA(19) = SP2 + ValHGap: CompA(20) = 0
 CompA(21) = (SP1 + ValWidth) - ValWGap: CompA(22) = SP2 + ValHeight: CompA(23) = 0


 Dim Speclayer1, Speclayer2 As AcadLayer
 Set Speclayer1 = ThisDrawing.Layers.Add("TComp")
 Dim color1 As AcadAcCmColor
 Set color1 = AcadApplication.GetInterfaceObject("AutoCAD.AcCmColor.18")
 Call color1.SetRGB(80, 100, 244)
 Speclayer1.TrueColor = color1
 ThisDrawing.ActiveLayer = Speclayer1
 

 Set plineObj = blockObj.AddPolyline(CompA)
 
    ' Define the attribute definition
    Dim attrComp As AcadAttribute
    Dim HeightComp As Double
    Dim ModeComp As Long
    Dim PromptComp As String
    Dim TagComp As String
    Dim ValueComp As String
    
    HeightComp = 1#
    ModeComp = acAttributeModeVerify
    PromptComp = "Constant Prompt"
    TagComp = "ITEM CODE"
    ValueComp = ComName & CompN
    
    Dim CompAtt As AcadAttribute
           
    ' Create the attribute definition object on the block
    Set CompAtt = blockObj.AddAttribute(HeightComp, ModeComp, PromptComp, insertionPnt, TagComp, ValueComp)
    Set CompAtt = blockObj.AddAttribute(HeightComp, ModeComp, PromptComp, insertionPnt, "Quantity", "1")


 'Insert the block
 Dim blockRefObj As AcadBlockReference
 insertionPnt(0) = SP1
 insertionPnt(1) = SP2
 insertionPnt(2) = 0
 Set blockRefObj = ThisDrawing.ModelSpace.InsertBlock _
 (insertionPnt, BlockName, 1#, 1#, 1#, 0)
End Sub
Posted
Comments
ZurdoDev 1-Mar-15 22:30pm    
The error does not seem very helpful. I would suggest going through documentation and making sure you are passing all the right parameters. Unfortunately it's sometimes hard to get a good error when using VBA to automate other apps.

See https://books.google.com/books?id=8BgC8yNkYvkC&pg=PA700&lpg=PA700&dq=AcadBlock+addattribute&source=bl&ots=mJx1GmSOw7&sig=eMWUNVKufG2mNSFjdJ9lvfDv9vg&hl=en&sa=X&ei=7NjzVLPrDrX7sAS5zYGQAQ&ved=0CDYQ6AEwAg#v=onepage&q=AcadBlock%20addattribute&f=false
Nikolai.Kimi 2-Mar-15 22:29pm    
Thanks RyanDev for the info.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900