I am trying to write a program in VB6 to automate the plotting of sheet set packages. It works great until I get to the point where I atcually have to access the AutoCAD ActiveX control. I have added the reference to AcSmComponents16 1.0 Type Library, as any of the other Autodesk components that I think might be needed. However, I get the error: "Specified module cannot be found" on this line: Set ssm = CreateObject("AcSmComponents.AcSmSheetSetMgr") Partial sample code: 'has the user selected a drawing package If lstdst.Text = "" Then MsgBox "You must select a drawing package to plot." Exit Sub End If ' open the database 'create the db filestring dstname = lstdst.Text msgstring = "selected package = " & dstname MsgBox msgstring If dstname = "WGVU 179051" Then dstname = "wgvu.dst" End If If dstname = "OETA 388041" Then dstname = "oeta.dst" End If If dstname = "PAPPAS 144051" Then dstname = "pappas.dst" End If If dstname = "SALES SAMPLE PACKAGE" Then dstname = "sample sales dwgs.dst" End If filestring = "\\signastor\engineering\sheet sets\" & dstname msgstring = "selected package = " & filestring MsgBox msgstring Set ssm = CreateObject("AcSmComponents.AcSmSheetSetMgr") Set db = ssm.OpenDatabase(filestring, True) ' lock the database Call db.LockDb(db) Any assistance would be appreciated. Thanks, Elise Moss www.mossdesigns.com
I think you need to use the GetInterfaceObject form of calling the library. Joe -- set packages. It works great until I get to the point where I atcually have to access the AutoCAD ActiveX control. the other Autodesk components that I think might be needed.
Nope, that doesn't help. I think the problem might be with the CreateObject call and not with the Autodesk library, so I am looking at that.
Private Sub Command1_Click() Dim ssm As AcSmSheetSetMgr Set ssm = CreateObject("AcSmComponents16.AcSmSheetSetMgr") 'note the "16" Set db = ssm.OpenDatabase(filestring, True) End Sub This gave me a '429' - ActiveX component can't create object.
check this google post http://groups-beta.google.com/group...zation.vba/browse_frm/thread/c98fc37678a6dd37 Dim ssm As ACSMCOMPONENTS16Lib.AcSmSheetSetMgr Dim db As AcSmDatabase Dim ss As AcSmSheetSet Sub changeNameNumber() Set ssm = CreateObject("AcSmComponents.AcSmSheetSetMgr") ' open the database Set db = ssm.OpenDatabase("C:\Program Files\AutoCAD 2005\Sample\Sheet Sets\Architectural\IRD Addition.dst", True) ' lock the database Call db.LockDb(db) 'etc hth Mark
I know nothing about sheet sets and even less about mucking with them programatically. But I was able to get his sample to run in vba. However when i try it in vb no ceegar. "Automation error The specified module could not be found. " Is that the same error you're getting? 'here's the code i tried 'adapted from above referenced google post Option Explicit Dim ssm As ACSMCOMPONENTS16Lib.AcSmSheetSetMgr Dim db As AcSmDatabase Dim ss As AcSmSheetSet Sub main() TestSheetSet End Sub Sub TestSheetSet() On Error GoTo whatsWrong 'this line works in vba but not in vb--- what's that about? Set ssm = CreateObject("AcSmComponents.AcSmSheetSetMgr") ' open the database Set db = ssm.OpenDatabase("C:\Program Files\AutoCAD 2005\Sample\Sheet Sets\Architectural\IRD Addition.dst", True) ' lock the database Call db.LockDb(db) ' get the sheetset Set ss = db.GetSheetSet Dim compEnum As IAcSmEnumComponent ' get component enumerator Set compEnum = ss.GetSheetEnumerator Call LoopThroughSheets(compEnum) ' unlock the database Call db.UnlockDb(db, True) ' close Call ssm.Close(db) exitHere: Set ss = nothing Set ssm = nothing Set db = nothing Exit Sub whatsWrong: If Err Then Debug.Print "SSM err: " & Err.Description Err.Clear End If On Error GoTo 0 Resume exitHere End Sub Private Sub LoopThroughSheets(ByVal compEnum As IAcSmEnumComponent) Dim comp As IAcSmComponent Set comp = compEnum.Next() ' loop through till the component is Nothing Do While Not comp Is Nothing On Error Resume Next Debug.Print comp.GetName & "," & comp.GetDesc On Error GoTo 0 ' if the component is a sheet, then... If comp.GetTypeName = "AcSmSheet" Then Dim s As AcSmSheet Set s = comp ' set the new number s.SetNumber "0000" ' set the new name s.SetTitle "MySheet" ' if the componnet is a subset then ... ElseIf comp.GetTypeName = "AcSmSubset" Then Dim sset As AcSmSubset Set sset = comp ' loop through all the sheets. Call LoopThroughSheets(sset.GetSheetEnumerator) End If ' next Set comp = compEnum.Next() Loop End Sub good luck hope you figure it out. I have a feeling there's so much wrong with the whole sheet set model it's a couple versions before it'll be worth trying to figure out how to use.
That is exactly the same error I am getting...ok, it may well be that the API does not work with VB, only with VBA...and I absolutely will not work in VBA (too restrictive). I am checking with Autodesk as well.
Joe's earlier suggestion that you use the GetInterfaceObject method of the AcadApplication class is most likely correct. Calling CreateObject from within a running instance of AutoCAD is not at all like calling CreateObject from a standalone application.
VBA...and I absolutely will not work in VBA (too restrictive). Well, that's what I thought too...not likely Joe is going to post mis-information! So this is what I tried...maybe I'm doing something wrong... (as usual) Option Explicit Dim ssm As ACSMCOMPONENTS16Lib.AcSmSheetSetMgr Dim db As AcSmDatabase Dim ss As AcSmSheetSet Sub main() TestSheetSet End Sub Public Function getACAD() As AcadApplication Dim app As AcadApplication On Error Resume Next Set app = GetObject(, "AutoCAD.Application") If Err Then Err.Clear Set app = CreateObject("AutoCAD.Application") If Err Then Exit Function End If Set getACAD = app End Function Sub TestSheetSet() Dim oAcad As AcadApplication On Error GoTo whatsWrong Set oAcad = getACAD If oAcad Is Nothing Then Debug.Print "Didn't get acad" Exit Sub End If ' Debug.Print "Got acad..." On Error Resume Next Set ssm = oAcad.GetInterfaceObject("AcSmComponents.AcSmSheetSetMgr") If Err Then Debug.Print "GetInterface failed..." & Err.Description Err.Clear Set ssm = GetObject("AcSmComponents.AcSmSheetSetMgr") If Err Then Debug.Print "GetObject failed..." & Err.Description Err.Clear Set ssm = CreateObject("AcSmComponents.AcSmSheetSetMgr") If Err Then Debug.Print "CreateObject failed..." & Err.Description Debug.Print "I give up" Err.Clear ' On Error GoTo 0 End If 'CreateObject End If 'GetObject End If 'GetINterface If Not ssm Is Nothing Then Debug.Print "Got ssm... " Else Exit Sub End If ' open the database Set db = ssm.OpenDatabase("C:\Program Files\AutoCAD 2005\Sample\Sheet Sets\Architectural\IRD Addition.dst", True) ' lock the database Call db.LockDb(db) ' get the sheetset Set ss = db.GetSheetSet Dim compEnum As IAcSmEnumComponent ' get component enumerator Set compEnum = ss.GetSheetEnumerator Call LoopThroughSheets(compEnum) ' unlock the database Call db.UnlockDb(db, True) ' close Call ssm.Close(db) exitHere: If Not oAcad Is Nothing Then Set oAcad = Nothing End If If Not ss Is Nothing Then Set ss = Nothing End If If Not ssm Is Nothing Then Set ssm = Nothing End If If Not db Is Nothing Then Set db = Nothing End If Exit Sub whatsWrong: If Err Then Debug.Print "SSM err: " & Err.Description Err.Clear End If On Error GoTo 0 Resume exitHere End Sub Private Sub LoopThroughSheets(ByVal compEnum As IAcSmEnumComponent) Dim comp As IAcSmComponent Set comp = compEnum.Next() ' loop through till the component is Nothing Do While Not comp Is Nothing On Error Resume Next Debug.Print comp.GetName & "," & comp.GetDesc On Error GoTo 0 ' if the component is a sheet, then... If comp.GetTypeName = "AcSmSheet" Then Dim s As AcSmSheet Set s = comp ' set the new number s.SetNumber "0000" ' set the new name s.SetTitle "MySheet" ' if the componnet is a subset then ... ElseIf comp.GetTypeName = "AcSmSubset" Then Dim sset As AcSmSubset Set sset = comp ' loop through all the sheets. Call LoopThroughSheets(sset.GetSheetEnumerator) End If ' next Set comp = compEnum.Next() Loop End Sub and heres' what I get:... Got acad... GetInterface failed...Problem in loading application GetObject failed...Automation error Invalid syntax CreateObject failed...Automation error The specified module could not be found. I give up The library all shows up in the object browser ok. Have you gotten this to work with GetInterfaceObject, Frank? Joe? anyone?
Assuming you all are using 2005, all you need to do is add a reference to the ACSMCOMPONENTS16Lib file. There is no need for Get/CreateObject or using the GetInterface. Below is a simple example but there is no error handling and it doesn't take into account if the ssmdatabase is locked. -- Mike ___________________________ Mike Tuersley ___________________________ the trick is to realize that there is no spoon... Sub test() Dim oSSM As New AcSmSheetSetMgr Dim ssmDbEnum As IAcSmEnumDatabase Dim ssmDbase As IAcSmDatabase Dim ssmShtSet As AcSmSheetSet Dim ssmEnum As IAcSmEnumComponent If Not oSSM Is Nothing Then Set ssmDbEnum = oSSM.GetDatabaseEnumerator If Not ssmDbEnum Is Nothing Then ssmDbEnum.Reset 'get the Database of the first sheetset Set ssmDbase = ssmDbEnum.Next If Not ssmDbase Is Nothing Then Set ssmShtSet = ssmDbase.GetSheetSet If Not ssmShtSet Is Nothing Then Set ssmEnum = ssmShtSet.GetSheetEnumerator LoopThruSheets ssmEnum End If End If End If End If End Sub Private Sub LoopThruSheets(ByRef ssmEnum As IAcSmEnumComponent) Dim ssmSheet As AcSmSheet Dim sNumber As String Dim sTitle As String Dim oComp As IAcSmComponent Set oComp = ssmEnum.Next() Do While Not oComp Is Nothing If oComp.GetTypeName = "AcSmSheet" Then Set ssmSheet = oComp Debug.Print ssmSheet.GetNumber Debug.Print ssmSheet.GetTitle Debug.Print ssmSheet.GetDesc ElseIf oComp.GetTypeName = "AcSmSubset" Then Dim ssmSubSet As AcSmSubset Set ssmSubSet = oComp Call LoopThruSheets(ssmSubSet.GetSheetEnumerator) End If Set oComp = ssmEnum.Next() Loop End Sub
I could not get your code to work. Clarifying that you are using Visual Studio VB6 (or better) and NOT VBA. The code broke on the first If Not statement for me - specified module not found. Thanks, everyone, for their efforts!
The SSM API is based on managed code and cannot be used with VB. -- Best Regards, Jimmy Bergmark CAD and Database Developer Manager at www.pharmadule-emtunga.com Blog: http://jtbworld.blogspot.com JTB FlexReport (FLEXnet / FLEXlm report tool) - www.jtbworld.com/jtbflexreport SmartPurger (Purges automatically) - www.jtbworld.com/?/smartpurger.htm or download some freeware at www.jtbworld.com More on AutoCAD 2005; www.jtbworld.com/autocad2005.htm
Can you then answer the question how SSM can be used in VB? Or is it just so that SSM API can only be used in managed code unless within VBA within AutoCAD? -- Best Regards, Jimmy Bergmark CAD and Database Developer Manager at www.pharmadule-emtunga.com Blog: http://jtbworld.blogspot.com JTB FlexReport (FLEXnet / FLEXlm report tool) - www.jtbworld.com/jtbflexreport SmartPurger (Purges automatically) - www.jtbworld.com/?/smartpurger.htm or download some freeware at www.jtbworld.com More on AutoCAD 2005; www.jtbworld.com/autocad2005.htm
You cannot use the SSM from an out-of-process ActiveX client. I won't get into the gory details, other than that the SSM is not OLE Automation- compatible, which is necessary in order for it to be accessable from a remote process. If you're using VB and working with a standalone windows application, you will need to build an ActiveX DLL that acts as an intermediary between the standalone app and the Sheet Set API. The ActiveX DLL can encapsulate the code that talks to the SSM (in the DLL code, you must use the 'new' keyword to create the AcSmSheetSetMgr instance, the GetInterfaceObject method will not work for this type of interface). If you're serious about AutoCAD programming, my first piece of advice for you, is to learn how to build and use ActiveX DLLs in VB, as they are essential for serious AutoCAD development.
See my other post, and visit MSDN and read up on what 'OLE Automation-compatible' means, and the limitations on ActiveX/COM servers that do not meet that requirement (as is the case with the SSM API). It has nothing to do with managed/unmanaged code. It is about in-process verses cross-process ActiveX. The SSM can be used from VB, provided the client is loaded into AutoCAD's process (e.g., an ActiveX DLL loaded with the GetInterfaceObject method). Since VBA is inherently an in-process client, there is no problem using SSM from there.
Almost forgot, there is one other requirement needed to use the SSM from an in-process VB ActiveX DLL, which is that the DLL code that calls the SSM must be executing in the application context. In other words, you can't load the dll from a Visual LISP function because the Visual LISP code executes in the document context, not the application context. To load a VB ActiveX dll that uses the SSM, you will need to use VBA. This requirement is mainly because the SSM has methods that open and activate documents, which as I'm sure you know, cannot be done from code that is running in the document context.