Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

VBA -Problems opening a new document in a running instance of BricsCAD.

 Can anyone point me to a working example of some VBA code running in a different application, that is able to create a new document in BricsCAD v14 without creating a new instance of it?

I have spent around a day and a half trying to figure this out. But the best I have been able to achieve is to always create a new instance of BricsCAD for the new document.  The examples I have come across so far always do this behavior.  So, perhaps BricsCAD behaves differently from AutoCAD in this regard, and my efforts to find a working BricsCAD example have failed.

To simplify things, I am OK, with the application not checking if BricsCAD is running or not, since I can simply require that the user always have BricsCAD already running.

This issue was presented in my thread titiled, "Using SendKeys VBA command from Excel"

The internal VBA help file for BricsCAD doesn't seem to provide this info as an example. (please correct me if I am wrong). Anyone know of a working example elsewhere, or where I am likely to find one?

-Joe

Comments

  •  I should give a few more details, in case they are important. I am on Windows 7 Pro, and running BricsCAD Plantinum 32 bit.

    IN trying to keep the tests as simple as possible, see the code below.  Running it with , or without BricsCAD already running, generates the error message on the line noted in a comment.

    [code]
    Sub test()
    Dim acadApp
    Dim acadDoc
    Set acadApp = GetObject(, "BricscadacadApp.AcadApplication") '<- Error #429 generated here.</span>
    Set acadDoc = acadApp.acadDocuments.Add  'open a new drawing document
    End Sub
    [/code]


    Thank you for any ideas or advice.
    -Joe
  •  I take it you were refering to the "Run as Administrator" part of that thread.  In my case, the security settings already in my operating system require that I always run BricsCAD as an administrator, and before it runs, it asks me to OK permitting BricsCAD to make changes to the computer.

    I did just try it by right-clicking on the BricsCAD icon in the start-up menu, and chose "run as administrator".  However, I got the same error at the same line.

    -Joe
  •  As I continue to make an effort to get back going with VBA, I am going to sites that talk about how to do it with AutoCAD.  And while I know a lot of the AuotCAD stuff is applicable to BricsCAD, I imagine that the specific task of opening BricsCAD itself and creating a document may be different.  Specifically, since these application examples don't work, that they must need to be tweaked in some way to be BricsCAD compatible.

    I am using a web page written in 2010 by Will at "How to AutoCAD", because it takes a very basic approach and explains every part of it.

    The 1st question is in relation to the VBA References.  There are both BricsCAD  and AutoCAD references available to me.  So, I have been loading both. Attached is a screen grab showing what I have loaded.

    His code for AutoCAD does not work as is.  I have also tried a few variations, but none have worked.  The autocomplete feature of VBA should, I think, be listing the types, as I start to type them. But, it does not.

    Here is the code he provides;
    Sub Main()    Dim ACAD As AcadApplication 'Create ACAD variable of type AcadApplication    Set ACAD = New AcadApplication 'Set the ACAD variable to equal a new instance of AutoCAD    ACAD.Visible = True 'Once loaded, set AutoCAD® to be visible    ACAD.ActiveDocument.Utility.Prompt "Hello from Excel!" 'Print a message to the AutoCAD® command lineEnd Sub  
    Is there any BricsCAD documentation about how to manage this sort of conversion from AutoCAD VBA code to BricsCAD?

    -Joe

    imageVBA CAD references.JPG
  • Public Sub NewDrawings()
       On Error Resume Next
       Dim NewDwg1 As AcadDocument
       Dim PATHandNAME As String
       Set NewDwg1 = ThisDrawing.Application.Documents.Add
       NewDwg1.Activate
       NewDwg1.WindowState = acNorm
       PATHandNAME = "C:\" & "ExistUserDefFold\" & "NewTestDoc" & ".dwg"
       NewDwg1.SAVEAS PATHandNAME
     End Sub

    Peter


  •  Thank you for the effort, but still no success, with or without BricsCAD already running. With or without a document already open.
    Does it work on your system?

    At first, nothing happened at all. Not even an error message. But once I remmed-out the On Error Resume line, and then ran it, it generated an error on the line that says,
       Set NewDwg1 = ThisDrawing.Application.Documents.Add

    Attached is the error, as well as the references I have already loaded.

    -Joe
    imageVBA Brcscad error Feb9.JPG
    imageVBA CAD references Feb8.JPG
  • In some of the other related threads I described the solution. But should mention it here as well. I turned out that my issues were caused by the security settings in my Win 7 system. BricsCAD had to be set to "run as administrator", and so Excel needed to be set to do that as well. First the Excel.exe file, and then the shortcut that I normally used to open Excel needed the setting.

    -Joe

This discussion has been closed.
Origami
Origami is the Japanese word for paper folding. ORI means to fold and KAMI means paper and involves the creation of paper forms usually entirely by folding.

Powered by VanillaForums, Designed by Steam