• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    .NET

    Reply
    Distinguished Contributor
    SRSDS
    Posts: 220
    Registered: ‎04-15-2011

    Changing system variables

    388 Views, 9 Replies
    08-01-2011 11:49 AM

    I want a few sendcommands executed when AutoCAD starts up. 

     

     Dim doc As Document = Application.DocumentManager.MdiActiveDocument        doc.SendStringToExecute("ANNOAUTOSCALE 4" & vbCr, False, False, True)       

     

    The DocumentCreated or DocumentActivated events doen't seem to trigger on start up so i've added them to the initialize sub. (Maybe the dll isn't loaded at this point)

     

    And in the initialize sub then they are ignored.Commandline looks like this:

    Command:

    AutoCAD menu utilities loaded.ANNOAUTOSCALE 4

    CANNOSCALE 1:100

    Command: _RIBBON

     

     If I put them in a routine they are slow and get minced in with other commands. Can anyone suggest a good place. Ir is SendStringToExecute not the right method?

    Please use plain text.
    Valued Mentor
    Posts: 488
    Registered: ‎03-18-2008

    Re: Changing system variables

    08-01-2011 12:47 PM in reply to: SRSDS

    You could try to set the variable programmitically instead of sending commands using:

     

    Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable(variable, value)

    Mike Robertson
    FL. Dept. of Transportation
    CADD Applications Developer

    HPxw4600 Workstation
    Core 2 Duo 2.33ghz, 8gb RAM
    nVidia Quadro FX1700
    Win7 64bit
    Please use plain text.
    Distinguished Contributor
    SRSDS
    Posts: 220
    Registered: ‎04-15-2011

    Re: Changing system variables

    08-01-2011 01:11 PM in reply to: michael.robertson

    Exactly what I'm after. 

    I got an error saying SetSystemVariable is not a member of Autodesk.AutoCAD.ApplicationServices.Application.

    But google it and found  Application.SetSystemVariable("MAXSORT", 100)

    Thankyou!

    Please use plain text.
    Distinguished Contributor
    SRSDS
    Posts: 220
    Registered: ‎04-15-2011

    Re: Changing system variables

    08-02-2011 01:16 AM in reply to: SRSDS

    Hi again.

    Is there a similar way to change the document variable settings?

    I also want to change things like the drawing annotation scale

     

     

    Please use plain text.
    Valued Contributor
    Posts: 88
    Registered: ‎03-17-2008

    Re: Changing system variables

    12-23-2011 08:30 AM in reply to: SRSDS

     


    SRSDS wrote:

    Hi again.

    Is there a similar way to change the document variable settings?

    I also want to change things like the drawing annotation scale

     

     


    Excellent Question!

     

    Anybody?  Does the document have to be opened and active?

     

    Thanks.

    Please use plain text.
    Mentor
    Posts: 241
    Registered: ‎05-12-2009

    Re: Changing system variables

    12-23-2011 08:39 AM in reply to: pjfontes

    Some you can set through the Database object like Database.Cannoscale if that is what you are talkink about

    You can also find your answers @ TheSwamp
    Please use plain text.
    Valued Contributor
    Posts: 88
    Registered: ‎03-17-2008

    Re: Changing system variables

    12-23-2011 08:56 AM in reply to: jeff

    Great!  I knew I was over-thinking it..

     

    Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument

     

    Dim acCurDb As Database = acDoc.Database

    acCurDb.Attmode = MyValue

     

     

    Please use plain text.
    Distinguished Mentor
    Posts: 839
    Registered: ‎09-07-2004

    Re: Changing system variables

    12-27-2011 04:04 PM in reply to: pjfontes

    You can use the following:

     

    Imports Autodesk.AutoCAD.ApplicationServices
    Try
        Dim lms As Object = Application.GetSystemVariable("CANNOSCALE")
        Application.SetSystemVariable("CANNOSCALE", lms)
    Catch ex As Autodesk.AutoCAD.Runtime.Exception
    End Try

     If a drawing is not open for a drawing based variable you will get an eInvalidInput exception. So you can mask that with the error trapping plus the error trapping helps if the version of AutoCAD does not support the variable you are using.

    Please use plain text.
    Mentor
    Posts: 241
    Registered: ‎05-12-2009

    Re: Changing system variables

    12-28-2011 09:46 AM in reply to: GTVic

    Why not use Database.Cannoscale?

    You can also find your answers @ TheSwamp
    Please use plain text.
    Distinguished Mentor
    Posts: 839
    Registered: ‎09-07-2004

    Re: Changing system variables

    12-28-2011 01:41 PM in reply to: jeff

    jeff wrote:

    Why not use Database.Cannoscale?


    I understood that CANNOSCALE was just an example of the type of variable he would like to set so my suggestion is a generic solution.

     

    On a side topic, I noticed that other 3rd party apps can have the problem of interrupting the startup sequence when using SendStringToExecute. When I had AutoCAD 2009 infected with the Adobe plug-in I would get an Adobe initialization message on the commandline followed by "Unknown command: OMMANDLINE" (missing the 'C') because AutoCAD was probably doing it's own SendStringToExecute of "COMMANDLINE" that was being interrupted by the Adobe plug-in. IMO, Autodesk shouldn't be programming its products this way but if you have to use SendStringToExecute I think there is a function you can call to make sure other commands are not being executed.

     

    DocumentManager.MdiActiveDocument.Editor.Document.CommandInProgress

     

    Or perhaps a document lock would work but I wonder if that could crash another plug-in that was trying to initialize. Assuming the other plug-in was not written properly.

    Please use plain text.