Results 1 to 4 of 4

Thread: ACADDOC.LSP error trapping

  1. #1
    Active Member
    Join Date
    2009-01
    Posts
    57
    Login to Give a bone
    0

    Default ACADDOC.LSP error trapping

    I've been building a ACADDOC.LSP for my company that sets most of the default system variables when a drawing is opened so we have typical settings on all of our detailer's PC's. One of the issues I've seen pop up while testing on my local machine is if a variable can't be set, such as CMLEADERSTYLE set to our current company MLEADER style, if the MLEADER style isn't available in the current drawing it will cause the script to error and stop processing the rest of the commands.

    I also notice, a couple of commands I had to nest using (setvar "varname" "value") and if the "value" range isn't acceptable, it errors, but then applies the next line of the script at the prompt for a valid range, it will just apply the next line in the ACADDOC.LSP. For example, UOSNAP help file has a range of 0 - 2, but ACAD only really accepts a range of 0 - 1. If 2 is set, it will prompt for input again, then apply the next command in the script UPDATETHUMBNAIL if you're keeping score at home.

    short of doing a huge IF SETVAR = is there a way to be able to have the startup routine verify settings are set, if not even a PRINC "things are broken" type error would be good enough.

    Just for troubleshooting, out of 729 variables, I'm setting 222 of them, every 50 lines of script I have it echo back "Loading" "successful" in two different lines so I can see the variables are still being paired correctly, or the words will be split across two SETVAR's making it easily spottable if a problem occurs, but it won't stop things from exploding.

    (The startup variables have all been dumped into EXCEL, parsed and various formulas applied to order the data they way I want it, with controls of which variable to pick up and set in ACAD using =IF AND CONCATINATE on how/what to organize.)

    I suppose I could set some USERSx variables as markers along the way as well, then verify if the setting is true to continue... hmm, just thought of that... It would still go sideways for however many lines I did a lookup to verify it's still set, but it MIGHT work well.

    Any ideas out there? I'm probably a intermediate level of programmer for .LSP, definitely not an expert!

  2. #2
    Certifiable AUGI Addict
    Join Date
    2001-03
    Location
    Tallahassee, FL
    Posts
    3,322
    Login to Give a bone
    0

    Default Re: ACADDOC.LSP error trapping

    UOSNAP overrides the DWFOSNAP, PDFOSNAP, and DGNOSNAP settings. Conversely, you can override the UOSNAP settings for DWF, DWFx, PDF, and DGN underlays by entering values for DWFOSNAP, PDFOSNAP, or DGNOSNAP system variables. A UOSNAP value of 2 basically means the UOSNAP value has been overridden. If you can't set a value for it at the command line you probably can't set it with a setvar either. Check the DWFOSNAP, PDFOSNAP, and DGNOSNAP settings instead.

    Here's how I generally check system variables:
    Code:
     (if (/= (getvar 'pickfirst) 1)(progn(setvar 'pickfirst 1)(princ "\nPick before command. PICKFIRST")))
    (if (> (getvar 'selectioncycling) 0)(progn(setvar 'selectioncycling (- (getvar 'selectioncycling)))(princ "\nTurn \"selectioncycling\" off. SELECTIONCYCLING")))
    (if (/= (getvar 'sortents) 127)(progn(setvar 'sortents 127)(princ "\nControls object sorting in support of draw order. SORTENTS")))
    I also have a few alerts like:
    Code:
     (if (getvar 'base)
      (alert "\"BASE\" set to something other than (0.0 0.0 0.0).")
    )
    (if (< 0.0 (distance (getvar 'insbase) '(0.0 0.0 0.0)))
      (alert "\"INSBASE\" set to something other than (0.0 0.0 0.0).")
    )
    (if (= (getvar 'MEASUREMENT) 1)
      (alert "Measurement:  1  <Metric>  \nDrawing uses metric support files.")
    )
    (if (= (getvar 'MEASUREINIT) 1)
      (alert "MEASUREINIT:  1  <Metric>  \nAutoCAD initial units set to metric support files.")
    )
    and my modemacro settings:
    Code:
     (setvar 'modemacro
        (strcat
             "$(If,$(Eq,$(Getvar,dbmod),0),,* )" 	;The asterick indiates the drawing is not saved.
             "$(getvar,cprofile)" 				;Current Profile
             ", $(getvar,wscurrent) "			;Current Workspace
             ", $(getvar,textsize) "
             "$(if,$(and,1,$(getvar,pickstyle)),<Group on> ,<Group off> )"
             "$(if,$(and,16384,$(getvar,osmode)),,$(if,$(and,1,$(getvar,osmode)),End ))"
             "$(if,$(and,16384,$(getvar,osmode)),,$(if,$(and,2,$(getvar,osmode)),Mid ))"
             "$(if,$(and,16384,$(getvar,osmode)),,$(if,$(and,32,$(getvar,osmode)),Int ))"
             "$(if,$(and,16384,$(getvar,osmode)),,$(if,$(and,2048,$(getvar,osmode)),App ))"
             "$(if,$(and,16384,$(getvar,osmode)),,$(if,$(and,4096,$(getvar,osmode)),Ext ))"
             "$(if,$(and,16384,$(getvar,osmode)),,$(if,$(and,4,$(getvar,osmode)),Cen ))"
             "$(if,$(and,16384,$(getvar,osmode)),,$(if,$(and,16,$(getvar,osmode)),Qua ))"
             "$(if,$(and,16384,$(getvar,osmode)),,$(if,$(and,256,$(getvar,osmode)),Tan ))"
             "$(if,$(and,16384,$(getvar,osmode)),,$(if,$(and,128,$(getvar,osmode)),Per ))"
             "$(if,$(and,16384,$(getvar,osmode)),,$(if,$(and,8192,$(getvar,osmode)),Par ))"
             "$(if,$(and,16384,$(getvar,osmode)),,$(if,$(and,8,$(getvar,osmode)),Nod ))"
             "$(if,$(and,16384,$(getvar,osmode)),,$(if,$(and,64,$(getvar,osmode)),Ins ))"
             "$(if,$(and,16384,$(getvar,osmode)),,$(if,$(and,512,$(getvar,osmode)),Nea ))"
             "$(If,$(Eq,$(Getvar,PStyleMode),0),STB ,CTB  )"
             "$(if,$(>, $(getvar,dynmode), 0),$(if,$(=,$(getvar,dynpicoords),0),@,  #),  #)"	;Dynamic coordinate entry.
             " $(getvar, cmdnames)"
        )
    )
    If you post a few lines of your acaddoc.lsp that aren't working the way you want we should be able to help you out.
    Tom Beauford P.S.M. - Civil 2020 on Windows 10 Enterprise
    Design Analysis - Leon County Public Works/Engineering Wrap [CODE] tags around selected text
    2280 Miccosukee Rd. Tallahassee, FL 32308-5310
    Ph# (850)606-1516 Home Page

  3. #3
    AUGI Addict
    Join Date
    2015-12
    Posts
    2,095
    Login to Give a bone
    0

    Default Re: ACADDOC.LSP error trapping

    I have a few generic conversion functions to smooth conversion between data types; when I set a system variable, first I get the type of the current value then pass the new value into the conversion function so it will always be an acceptable type. I also error-trap setting system variables in case a rogue values leaks through. And all of *that* is wrapped in a generic system variable function so all system variables are treated the same way, and can be handled with lists. For start-up conditions, the system variable settings are in data files rather than code, so they can be updated without needing to dig over, under, and through code to find values to change/add/remove.
    If you are going to fly by the seat of your pants, expect friction burns.
    Some say beauty is in the eye of the Beholder... perhaps so, but I've only seen the disintegration beam.
    Everyone else being wrong is not the same thing as being right.

  4. #4
    Administrator rkmcswain's Avatar
    Join Date
    2004-09
    Location
    Earth
    Posts
    9,754
    Login to Give a bone
    0

    Default Re: ACADDOC.LSP error trapping

    Quote Originally Posted by jasonp View Post
    Just for troubleshooting, out of 729 variables, I'm setting 222 of them
    Are any of those drawing saved variables, and if so can you just set them in your template drawing(s)?


    One of the issues I've seen pop up while testing on my local machine is if a variable can't be set, such as CMLEADERSTYLE set to our current company MLEADER style, if the MLEADER style isn't available in the current drawing it will cause the script to error and stop processing the rest of the commands.
    For cases like this, always assume that the target object will not be available. Either test for it before trying to set it, or just brute force create/recreate it again then do your "set".
    R.K. McSwain | CAD Panacea |

Similar Threads

  1. Questions on error trapping
    By JaCAD in forum AutoLISP
    Replies: 3
    Last Post: 2011-03-04, 04:47 PM
  2. Error Trapping
    By jmcshane in forum AutoLISP
    Replies: 6
    Last Post: 2008-12-21, 02:56 AM
  3. Error Trapping
    By prose in forum AutoLISP
    Replies: 4
    Last Post: 2008-12-05, 10:02 PM
  4. If Statements & error trapping
    By planview in forum AutoLISP
    Replies: 0
    Last Post: 2006-05-29, 08:46 AM
  5. nested error trapping used incorrectly
    By Bob Eardley in forum AutoCAD General
    Replies: 5
    Last Post: 2005-09-14, 10:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •