Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Check String to set up a dimstyle

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
dcampbellhutchinson
954 Views, 6 Replies

Check String to set up a dimstyle

Hello All,

 

I've been working on a lisp to set up basic settings such as text styles, dim styles, discipline specific layers and things of that nature.

 

I have a prompt to ask for a discipline designator as a string.  I want to have an If statement or a conditional to read that string and check for a "C" if it finds it I want to have it set up a dimstyle to decimal feet ect and if not do it as architectural units.

 

This is just a test lisp that I'd like to add to the main one listed above... Any suggestions are greatly appreciated!

 

Thanks in Advance!

 

 

 

(defun c:test(/ disc dsnm dsna)

  (setq disc (getstring "\nDiscipline (G,C,S,M,E,CP): "))                ;Prompt for Discipline
  (setq ds (getint "\nDimscale Factor: "))                                          ;Prompt for Dimscale

  (setq dsnm (itoa ds))                        ;Turns Dimscale into String for Dimension Name
 
  (if (or (null disc)(= disc "C"))            ;Checks to see if Civil dimstyles are needed

    ((setq dsna (strcat "CEI - " dsnm " Arrow"))        ;Creates Dimstyle CEI [dimscale] Arrow

     (if (not (tblsearch "dimstyle" dsna))                     ;Checks to see if Dimstyle Name already exists
     (command ".-dimstyle" "s" dsna))

        ;;From Lines Tab:
    (SETVAR "DIMCLRD" 1)               ;Dimension line and leader color
    (SETVAR "DIMCLRE" 1)               ;Extension line color
    (SETVAR "DIMEXE" 0.0625)          ;Extension above dimension line
    (SETVAR "DIMEXO" 0.0625)           ;Extension line origin offset
    ;;From Symbols & Arrows Tab
    (SETVAR "DIMBLK" ".")        ;Arrow block name
    (SETVAR "DIMBLK1" ".")            ;First arrow block name
    (SETVAR "DIMBLK2" ".")           ;Second arrow block name
    (SETVAR "DIMLDRBLK" ".")        ;Leader block name
    (SETVAR "DIMASZ" 0.125)               ;Arrow size
    ;;From Text Tab
    (SETVAR "DIMTXSTY" "ROMANS")       ;Text style
    (SETVAR "DIMCLRT" 2)        ;Dimension text color
    (SETVAR "DIMTXT" ts)               ;Text height
    (SETVAR "DIMTFAC" 0.75)         ;Tolerance text height scaling factor
    (SETVAR "DIMTAD" 1)               ;Place text above the dimension line
    (SETVAR "DIMGAP" 0.0625)        ;Gap from dimension line to text
    (SETVAR "DIMTIH" 0)                ;Text inside extensions is horizontal
    (SETVAR "DIMTOH" 0)               ;Text outside horizontal
    ;;From Fit Tab
    (SETVAR "DIMTMOVE" 1)             ;Text movement
    (SETVAR "DIMSCALE" ds)            ;Overall scale factor
    ;;From Primary Units Tab
    (SETVAR "DIMLUNIT" 4)              ;Linear unit format (Architectural now)
    (SETVAR "DIMDEC" 4)               ;Decimal places
    (SETVAR "DIMFRAC" 1)              ;Fraction format
    (SETVAR "DIMZIN" 3)              ;Zero suppression

     (command "-dimstyle" "s" dsna "Y"))

   (t
    (princ "\nNo Civil Dimstyles Added.")
   )
  )


6 REPLIES 6
Message 2 of 7


@dcampbellhutchinson wrote:

....  I want to have an If statement or a conditional to read that string and check for a "C" if it finds it I want to have it set up a dimstyle to decimal feet ect and if not do it as architectural units.

.... 

  (setq disc (getstring "\nDiscipline (G,C,S,M,E,CP): "))                ;Prompt for Discipline
.... 
  (if (or (null disc)(= disc "C"))            ;Checks to see if Civil dimstyles are needed
    ((setq dsna (strcat "CEI - " dsnm " Arrow"))        ;Creates Dimstyle CEI [dimscale] Arrow
....

     (command "-dimstyle" "s" dsna "Y"))
   (t

    (princ "\nNo Civil Dimstyles Added.")
   )
  )


I think you have some elements of (if) and (cond) functions interbreeding there....  Try either something like this:

 

  (if (or (null disc) (= disc "C"))            ;Checks to see if Civil dimstyles are needed
    (progn ; 'then' argument [progn to include more than one function in one argument]

      (setq dsna (strcat "CEI - " dsnm " Arrow"))        ;Creates Dimstyle CEI [dimscale] Arrow
....

      (command "-dimstyle" "s" dsna "Y")

    ); end progn and 'then' argument

    (princ "\nNo Civil Dimstyles Added.") ; 'else' argument
  ); end if

 

or like this:

 

  (cond

    ((or (null disc) (= disc "C"))           ;Checks to see if Civil dimstyles are needed
      (setq dsna (strcat "CEI - " dsnm " Arrow"))        ;Creates Dimstyle CEI [dimscale] Arrow
....

      (command "-dimstyle" "s" dsna "Y")

    ); end first condition
    (t ; no prior condition was satisfied

      (princ "\nNo Civil Dimstyles Added.")
    ); end otherwise-fallback condition
  ); end cond

 

EDIT:

Come to think of it, the second one could be without the True-test element -- just:

 

  (cond

    ((or (null disc) (= disc "C"))           ;Checks to see if Civil dimstyles are needed
      (setq dsna (strcat "CEI - " dsnm " Arrow"))        ;Creates Dimstyle CEI [dimscale] Arrow
....

      (command "-dimstyle" "s" dsna "Y")

    ); end first condition
    ((princ "\nNo Civil Dimstyles Added.")); no prior condition satisfied

  ); end cond

Kent Cooper, AIA
Message 3 of 7

>...Any suggestions are greatly appreciated!

>

 

Look into (INITGET "G C S M E CP") and change GETSTRING to GETKWORD.

Review the documentation for INITGET and GETKWORD - they are meant for each other...

However, I see you will only use one of 2 dimension type - meaning not 6

different dimension types as you are asking with your getstring statement.

 

Build you a fool-proof dialog box using DCL.

Looks like some radio_buttons are in order as well as list_box for the DIMSCALE.

 

As far as the DIMVARS, create a stand-alone program to load these settings

for your typical situation, then for any other type of dimension style, simply set (at

the most) the three switches that makes a new dimension style. You can either

keep these as overrides (by not saving), or "DIM" "Save" "MyDimstyle" "Exit"

to create the unique dimension style. If the earlier as overrides, to return back to

the "base" dimension style, simply "DIM" "Restore" "MyDimstyle" "Exit" and the

overrides will disappear.

 

???

 


Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.


Message 4 of 7

I see what you guys are saying...I'll have 4 different dimension styles total each named differently pending the dimscale and with a few other specific variables.

 

So if I define them as separate functions within this lisp, how would I write the conditional or the if then statment to call the functions?  Would it just be (Command "function name")?  I'm having a hard time trying to refrain from subconsiously using VBA language here

 

I apologize I know enough lisp to get by and I've been chipping away at this one for a while trying to brush up on it a bit. Kent helped with the Dimstyle previously.  I still have plans to try and add multileader styles and table styles as well.  So I guess if you guys have any ideas on those that would appreciated.  Since they don't have system variables I might be forced to load a template of some sort, which I was hoping to avoid.

 

Radio buttons would be nice, but I only know how to do that with VBA.  If possible I'd like to keep as much of the set-up in the single lisp file as possible, just to keep it simple.

 

Thanks Again!

Message 5 of 7

Ok so I've got the if then statement working thanks to Kent, and I've defined the specific dimstyles as their own functions (thanks scott) within this same lisp... Question is how do I call them in the if then statement, I read and attempted that you can't use  

 

(if (= disc C) (command "[my dimstyle function1]") (command "[my dimstyle function2]"))

 

Also any ideas as to adding table styles and Multileader styles would be appreciated as well.

 

Thanks & have a good weekend!

Message 6 of 7


@dcampbellhutchinson wrote:

Ok so I've got the if then statement working thanks to Kent, and I've defined the specific dimstyles as their own functions (thanks scott) within this same lisp... Question is how do I call them in the if then statement, I read and attempted that you can't use  

 

(if (= disc C) (command "[my dimstyle function1]") (command "[my dimstyle function2]"))

....


If you're calling functions defined with (defun C:...), you can't use the (command) function, which only recognizes AutoCAD commands.  You call them with (C:functionname):

 

(if (= disc C)

  (C:[my dimstyle function1])

  (C:[my dimstyle function2])

)

Kent Cooper, AIA
Message 7 of 7

Again... Kent, you have torn down another road block.  Thanks Man!

 

The next addition is adding multileader styles and table styles... since we don't get any variables for either of those I'm loathing the idea of inserting them in as blocks and cancelling the command or simply bringing them in from a template.

 

Thanks again!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost