VBA is not identifying "ThisDrawing"

VBA is not identifying "ThisDrawing"

nitin.rathod3CW9S
Contributor Contributor
1,814 Views
3 Replies
Message 1 of 4

VBA is not identifying "ThisDrawing"

nitin.rathod3CW9S
Contributor
Contributor

My VBA code is not identifying/compiling "ThisDrawing", May be I'm missing any reference or library?

below is the screenshot of the compile error it shows. I've also copied the sub in case anybody wants to help me.

2021-03-16_19-16-17.jpg

 

'reference to "Autodesk SymBBAuto 4.0 Type Library".

Sub createPartReference()
Dim oAcApp As AcadApplication
Dim oAcUtil As AcadUtility
Set oAcApp = GetObject(, "AutoCAD.Application")
Set oAcUtil = oAcApp.ActiveDocument.Utility

Dim oAcDwg As AcadDocument
Set oAcDwg = oAcApp.ActiveDocument
'oAcApp

Dim pt As Variant
pt = oAcUtil.GetPoint(, "Location for ampartref: ")
pt = oAcUtil.TranslateCoordinates(pt, acUCS, acWorld, False)
Dim oPartref As McadPartReference
'Set oPartref = oAcDwg.ModelSpace.AddCustomObject("AcmPartRef")
Set oPartref = ThisDrawing.ModelSpace.AddCustomObject("AcmPartRef")
oPartref.Origin = pt

Dim oSymbb As McadSymbolBBMgr
Set oSymbb = ThisDrawing.Application.GetInterfaceObject("SymBBAuto.McadSymbolBBMgr")
'Set oSymbb = oAcDwg.Application.GetInterfaceObject("SymBBAuto.McadSymbolBBMgr")
Dim oBommgr As McadBOMMgr
Set oBommgr = oSymbb.bomMGR

Dim pdata(0 To 5, 0 To 1) As String
pdata(0, 0) = "DESCR": pdata(0, 1) = "My Description"
pdata(1, 0) = "STANDARD": pdata(1, 1) = "My Standard"
pdata(2, 0) = "MATERIAL": pdata(2, 1) = "My material"
pdata(3, 0) = "NOTE": pdata(3, 1) = "My note"
pdata(4, 0) = "VENDOR": pdata(4, 1) = "My vendor"
pdata(5, 0) = "NAME": pdata(5, 1) = "Comp1"

oBommgr.SetPartData oPartref, pdata
ThisDrawing.Application.Update
'oAcDwg.Application.Update
End Sub

 

0 Likes
1,815 Views
3 Replies
Replies (3)
Message 2 of 4

Ed__Jobe
Mentor
Mentor

Apparently you are using Excel VBA or some other program. The objects AcadApplication and ThisDrawing are only created when you are working on VBA within AutoCAD. Otherwise you need to create your own variables. You can use ThisDrawing if you want, using

 

ThisDrawing As AcadDocument

ThisDrawing = Application.ActiveDocument

 

Don't forget that if you switch active documents, you need to update your variable since you're not working in AutoCAD's VBA.

 

In your code, instead of:

ThisDrawing.Application.GetInterfaceObject

you should have used:

oAcApp.GetInterfaceObject

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 3 of 4

nitin.rathod3CW9S
Contributor
Contributor

thanks for response.

Like you guessed, I'm using excel VBA.

If you scroll above, I've tried creating my own active document with name "oAcDwg" but then It changes the error message to "Type mismatch". 

2021-03-16_19-22-47.jpg

0 Likes
Message 4 of 4

Ed__Jobe
Mentor
Mentor

I can't tell at which line the error occurs. When you are setting the document or the partref?

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes