Help: 2nd run wrongly, a small customized command

Help: 2nd run wrongly, a small customized command

Anonymous
Not applicable
424 Views
4 Replies
Message 1 of 5

Help: 2nd run wrongly, a small customized command

Anonymous
Not applicable

Hi Guys,
Just did a simple customized command PLA (see attached "platform.lsp"), the problem is for the 1st running the command works correctly, it creates one beam and one post ("1st run - work correctly.jpg" as attached), it works wrongly if you run the command 2nd time ("2nd run - post cannot be drawn.jpg" as attached).

My guessing is there are some issues with the BOX command, but have no idea how to fix it.

Could you guys do a quick run on your computer and help me on this?

 

1st run - work correctly.jpg

2nd run - post cannot be drawn.jpg

0 Likes
Accepted solutions (1)
425 Views
4 Replies
Replies (4)
Message 2 of 5

Ajilal.Vijayan
Advisor
Advisor
Accepted solution

Turn off 2D and 3D Objectsnap (F3 & F4) and try.

 

I have added lisp code to turn off 2D and 3D snap before the box command and the code will reset the snap values once the box command completed.

Click the +sign to see the Code

Spoiler
 
(defun Draw3D( / osmod 3dosmod)
;Get the Current value of 2D and 3D snap (setq osmod (getvar "osmode")) (setq 3dosmod (getvar "3dosmode")) ;Turn off 2D and 3D snap (setvar "osmode" 0) (setvar "3dosmode" 1) (Drawbox Basepoint TrussSecW wid TrussSecH);draw truss 1 top beam (SETQ BeamHigh (- 0 (+ hig (* wid (/ (sin angRad) (cos angRad)))))) (Drawbox Basepoint TrussSecW TrussSecH BeamHigh);draw truss 1st post ;restore 2D and 3D snap (setvar "osmode" osmod) (setvar "3dosmode" 3dosmod) );Draw3D

Also all the variables in your code is not declared as local variables.

You need to consider to declare the variables locally.

As the sub functions are sharing the variables, you can declare the variables locally at the main function.

Something like..

(defun C:PLA ( / len wid ang hig NoTruss angRad NoBeam TrussSecH..........)

To declare local variables

Message 3 of 5

Anonymous
Not applicable

Thanks Ajilal,

 

Mesa got it solved. Thanks for your suggetion on using local variables.Cat Happy  Will try more later on.

0 Likes
Message 4 of 5

Ajilal.Vijayan
Advisor
Advisor

Welcome to Autodesk Community !!

Glad I could help.

0 Likes
Message 5 of 5

BeKirra
Advisor
Advisor

Based on your description, you may noticed that the 2nd run inserts the "truss" to the same place of the one created in the 1st run.

Therefore you may need to add an insertion function to yor main code "PLA" for verifying the insert point for 2nd truss frame.

With my additional lines below, you don't have to type "PLA" running your code for 2nd time for next truss frame. It will continue until you hit "enter" key by not selecting any point for next truss.

Your next step may be looking into "Error Handler" function for resetting system variables suggested by A.V.

 

HTH

(defun C:PLA ( )
 
  (readinput); read in platform length, width, angle, shorter side height, grating thickness
  
  (Caculate);
  
  (SectionPreset);

  ; = = = = = = = = = = = = = = = =
  ; new lines
  (if (null Insertpoint)
  (progn (setq Basepoint (list 0 0))
  (Draw3D)
  )
  )
  
  (while (setq Insertpoint (getpoint "\nSelect a point for Truss:"))
  (setq Basepoint Insertpoint)
  (Draw3D);
  )
  ; end of new lines
  ; = = = = = = = = = = = = = = = =
  
); end defun

 

Please mark "Accept as Solution" and "Like" if my reply resolves the issue and it will help when others need helps.
= ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ =
A circle is the locus of a cursor, starting and ending at the same point on a plane in model space or in layout such that its distance from a given coordinates (X,Y) is always constant.
X² + Y² = C²
0 Likes