Command-S

Command-S

CCALERQV3S
Observer Observer
1,048 Views
14 Replies
Message 1 of 15

Command-S

CCALERQV3S
Observer
Observer

My lisp routine isn't working anymore. Can you help me with this?

 

 Moderator Edit** Post your code in a code window.
                                                                              
;                                                                                                                  
;                                                                                        
;C:SOLID_WEIGHT FUNCTION TO FIND THE WEIGHT OF A SOLID OR SET OF SOLIDS. ALERTS OF WEIGHT
;OR FILLS OUT WEIGHT BLOCK IF FOUND                                                      

(DEFUN C:SOLWT ( / WEIGHT done fp line ofp v ss1 weight_block weight_block_SS matltype matlfact atts WEIGHTLB wb)
  (initerr)
  (setq fp "c:/temp/solid_weight.mpr")
  (setq ofp (open fp "w"))
  (close ofp)
  (prompt "\nSelect objects to weigh...")
  (setq ss1 (ssget))
  (initget 1 "S CC SS A 2 G C I")  
  (setq matltype (getkword "Select material type (<S>A36/A588/A514/AR360 <CC>Chrome Carbide <SS>304/316 Stainless <A>ALUMINUM <2>2205 Stainless <I>Inconel 625 <G>HASTELLOY B-582 <C>HASTELLOY B-575: "))
  (cond
    ((= matltype "S")
      (setq matlfact 7.841805)
    )
    ((= matltype "CC")
      (setq matlfact 8.248705)
    )
    ((= matltype "G")
      (setq matlfact 8.58086660)
    )      
    ((= matltype "SS")
      (setq matlfact 8.0272623)
    )
    ((= matltype "A")
      (setq matlfact 2.71266105)
    )
    ((= matltype "2")
      (setq matlfact 7.69509970) 
    )
    ((= matltype "C")
      (setq matlfact 8.885)
    )
    ((= matltype "I")
      (setq matlfact 8.44246550)
    )
  )
  (IF SS1
    (PROGN      
      (command "_massprop" ss1 "" "y" fp )  
      (setq ofp (open fp "r"))
      (while (and (not done)(/= (setq line (read-line ofp)) nil))
        (if (= (instr line "Volume") 1)
          (progn
            (setq v (atof (substr line 26)))
            (setq done t)
          )
        )
      )
      (close ofp)
      (if (= "M" (strcase (get_default "METRIC-ENGLISH" "defaults.dat")))
        (SETQ WEIGHT (* (* matlfact 0.000001) V)) ; need to adjust this is for metric models
        (SETQ WEIGHT (* 16.387048667871174969170323209728 (* (* matlfact 0.001) V))) ; need to adjust this for english models                    
      )
      (SETQ WEIGHTLB (* WEIGHT 2.2046))
      (setq wb (ssget  "X" (list (CONS 2 "WEIGHT")(CONS 0 "INSERT")(CONS 410 (GETVAR "CTAB")))))
      (if wb
        (setq weight_block (ssname wb 0))
        (IF (/= (setq clayout (STRCASE (getvar "ctab"))) "MODEL")
      (PROGN
        (COMMAND "PSPACE")
        (setq attdia_sav (getvar "attdia"))
        (setq ATTREQ_SAV (getvar "ATTREQ"))
                (setvar "attdia" 0)                       
                (setvar "ATTREQ" 0)
        (default_layer "dimension")
        (setq oldsnap (getvar "osmode"))
        (setvar "osmode" 0)
        (command "_insert"  "WEIGHT"  "8.5522,57.9783,0" "1" "" "0")
        (setvar "osmode" oldsnap)
        (PREV_LAY)
        (setvar "ATTREQ" ATTREQ_SAV)
        (setvar "attdia" attdia_sav)
        (setq wb (ssget  "X" (list (CONS 2 "*WEIGHT")(CONS 0 "INSERT")(CONS 410 (GETVAR "CTAB")))))
        (setq weight_block (ssname wb 0))
      )
        )
      )     
      (setq atts (append (list (list "WEIGHT" (STRCAT (rtos WEIGHTLB 2 3) " lbs."))) atts))
      (IF weight_block
        (ATT_REP weight_block atts)
        (alert (strcat "\nWeight of selected solids is " (rtos weight 2 2) " Kg." "\n" (rtos WEIGHTLB 2 3) " Lbs."))
      )  
      WEIGHTLB
    )
  )
  (RESET)
)​
0 Likes
Accepted solutions (1)
1,049 Views
14 Replies
Replies (14)
Message 2 of 15

Ed__Jobe
Mentor
Mentor

You haven't provided any information by which people can help you. What's not working? What does it do wrong? Are there any error messages?

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 3 of 15

CCALERQV3S
Observer
Observer

I figured it out. The routine references a "temp" folder, and I didn't have one.

0 Likes
Message 4 of 15

john.uhden
Mentor
Mentor

@CCALERQV3S ,

I am glad to hear that you have apparently found and fixed a shortcoming.

But I am also curious about these two lines:

  (initget 1 "S CC SS A 2 G C I")  
  (setq matltype (getkword "Select material type (<S>A36/A588/A514/AR360 <CC>Chrome Carbide <SS>304/316 Stainless <A>ALUMINUM <2>2205 Stainless <I>Inconel 625 <G>HASTELLOY B-582 <C>HASTELLOY B-575: "))

It won't accept my response of A36 or A514, etc.

Plus, it is the habit of most AutoLispers to indicate a default response within <>, but you are indicating a number of defaults of which there can be only one, allowing the user to provide a null response by just hitting the "Enter" key.  But your (initget 1 ...) requires a response.

 

 

John F. Uhden

0 Likes
Message 5 of 15

paullimapa
Mentor
Mentor
Accepted solution

@CCALERQV3S I agree with @john.uhden 

There should be an option to accept a default value for initget and since you want to provide an explanation as to what the abbreviations mean I would modify the code with the following:

 

(not **matltype** (setq **matltype** "C")) ; set default global variable
(setq choiceinitget "S CC SS A 2 I G C" ; choice for initget
      choicegetkword (strcat "[" (vl-string-translate " " "/" choiceinitget) "] <" **matltype** ">: ") ; choice for getkword
      choiceprinc "\nSelect material type:\n<S>A36/A588/A514/AR360 <CC>Chrome Carbide <SS>304/316 Stainless <A>ALUMINUM\n<2>2205 Stainless <I>Inconel 625 <G>HASTELLOY B-582 <C>HASTELLOY B-575:"
)
(princ choiceprinc) ; princ message on screen explaining abbreviations
(initget choiceinitget)(setq matltype (getkword choicegetkword)) ; initget+getkword
(if(not matltype)(setq matltype **matltype**)(setq **matltype** matltype)) ; if user hits enter vs selecting new value

 

Now at the getkword prompt, you can actually select one of the abbreviations or just hit enter to accept the default

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 6 of 15

Sea-Haven
Mentor
Mentor

I dont use initget anymore rather made a lisp for creating dcl on the fly. You can set any button as default. Even say repeat last selected.

 

SeaHaven_0-1716163682491.png

(if (not AH:Butts)(load "Multi radio buttons.lsp")) ; loads the program if not loaded already
(setq ans (ah:butts 1 "V"   '("Please choose" "A36/A588/A514/AR360" "Chrome Carbide" "304/316 Stainless" "ALUMINUM" "2205 Stainless" "Inconel 625" "HASTELLOY B-582" "HASTELLOY B-575")))

 

Message 7 of 15

john.uhden
Mentor
Mentor

Thanks, Paul.

I am still distressed with all the <> which do not represent defaults.

I think his users would be much better served by selecting from a dialog box, where they don't have to interpret the keyword or type in a lengthy response, and yes, it could be set for a default value where they could just hit the Enter key.

John F. Uhden

0 Likes
Message 8 of 15

Kent1Cooper
Consultant
Consultant

By the way, a little "point of order" about this line:

(SETQ WEIGHT (* 16.387048667871174969170323209728 (* (* matlfact 0.001) V)))

AutoCAD cannot keep track of more than 16 significant figures, so the precision of the first number there is ludicrously far beyond what it can possibly handle.  And nested multiplications can just be made into one multiplication of all the parts involved.  And two of those numbers can just be combined by shifting the decimal place in the first one.  This will do it all for you, to as great a precision as AutoCAD can deal with:

(SETQ WEIGHT (* 16387.04866787117 matlfact V))

[Still need to adjust this for english models]

Kent Cooper, AIA
0 Likes
Message 9 of 15

paullimapa
Mentor
Mentor

Dialog boxes are great but not effective for running scripts. Initget & getkword when combined with the proper DYNMODE setting can actually provide a valid gui alternative.  Maybe instead of <> the description list should use () just as a way to indicate what the abbreviation represents. But I think that’s up to the user or programmer to decide 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 10 of 15

john.uhden
Mentor
Mentor

Kent:

Well put, but umm, that was 0.001, not 1000.

John F. Uhden

0 Likes
Message 11 of 15

Kent1Cooper
Consultant
Consultant

And I suggest you spare yourself all the individual condition checks on the material type with their individual separate coding for the setting of the factor variable.  You can spell out just one setting of that variable, using an association list from which to extract that value:

(setq matlfact
  (cadr
    (assoc matltype
      '(("S" 7.841805) ("CC" 8.248705) ("G" 8.5808666) ("SS" 8.0272623)
        ("A" 2.71266105) ("2" 7.6950997) ("C" 8.885) ("I" 8.44246550)
      ); association list
    ); assoc
  ); cadr
); setq

 

Kent Cooper, AIA
0 Likes
Message 12 of 15

john.uhden
Mentor
Mentor

@paullimapa ,

It didn't appear to me that he was running a script.

I never use scripts.  Can you even include an AutoLisp call in a script?

John F. Uhden

0 Likes
Message 13 of 15

Ed__Jobe
Mentor
Mentor

@john.uhden Scripts can include whatever you would type at the command line, and you can type lisp at the command line. So Yes, scripts can include lisp.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

Message 14 of 15

paullimapa
Mentor
Mentor

not that scripting is required but that option can be executed with the current code.


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 15 of 15

john.uhden
Mentor
Mentor

@Ed__Jobe ,

Thanks for that explanation.

So, I take it that a script CAN invoke a DCL, indirectly.

John F. Uhden

0 Likes