Anuncios

The Autodesk Community Forums has a new look. Read more about what's changed on the Community Announcements board.

Lisp Routine wont work on other computer.

MRummler
Contributor

Lisp Routine wont work on other computer.

MRummler
Contributor
Contributor

I have a lisp that is meant for lined duct work that i created for myself. I tried to give it to a coworker and it failed to work in their AutoCAD only drawing half of the lined duct... when he tried my reducer it was all in the same x coordinate making it look like a straight line up the y axis. Why does it work for me and not him? (p.s. I have AutoCAD 2017, he has AutoCAD 2018.) 

 

Here is my straight lined duct code below.

 

 

(defun c:NewLinedDuct ()
  (setvar "orthomode" 1)
  (setq layr (getvar "clayer"))
  (if (= ds nil)
    (setq ds 999)
  )
  (if (= ds 999)
    (progn
      (setq ds	(getreal "\nSheet metal Size?")
	    ld	(getreal "\nEnter Liner Width")
	    pt1	(getpoint "\nSelect Starting Point...")
      )
      (setq pt2 (getpoint pt1 "\nSelect End Point"))
    )
    (progn
      (setq pt2 (getpoint pt1 "\nSelect End Point"))
    )
  )
  (command "-layer" "m" "M-DUCT" "c" "magenta" "M-DUCT" "")
  (setq an1 (angle pt1 pt2))
  (command "line" pt1 pt2 "")
  (setq	ss1 (ssget pt1)
	nm1 (/ ds 2)
  )
  (setq nm2 (- nm1 ld))
  (setq	pt3 (polar pt1 (- an1 (/ pi 2.0)) 1)
	pt4 (polar pt1 (+ an1 (/ pi 2.0)) 1)
  )
;pt3 is point on one end of line
;pt4 is point on other end of line
;(it doesnt matter which is which side for now.)
  (command "offset" nm1 ss1 pt3 "")
  (command "offset" nm1 ss1 pt4 "")
  (command "chprop" ss1 "" "c" "Green" "LT" "Hidden2" "")
  (command "offset" nm2 ss1 pt4 "")
  (setq ssx (ssget "l"))
  (command "offset" nm2 ss1 pt3 "")
  (setq ssy (ssget "l"))
  (command "erase" ss1 "")
  (setvar "clayer" layr)
  (if (and ssxt ssyt)
    (progn
      (command "fillet" ssx ssxt)
      (command "fillet" ssy ssyt)
      (setq ssyt nil
	    ssxt nil)
      )
    )
  (setq pt1 pt2)
  (setvar "snapang" an1)
  (princ)
)

 

0 Me gusta
Responder
Soluciones aceptadas (1)
960 Vistas
7 Respuestas
Respuestas (7)

scot-65
Advisor
Advisor
Without trying your utility:
(setq ss1 (ssget pt1)
will become a selection set.
"ss1" is not needed as shown below.

Offset expects a point selection and not a object [for your case it is a member of a selection set].
Try selecting the newly created object using polar:
(setq pt1 (polar pt1 an1 (/ (distance pt1 pt2) 2.0)))

Now it's ready:
(command-s ".Offset" nm1 pt1 pt3 "")

Other items to consider is to suppress OSMODE. Once the user has input the values,
add 16384 to OSMODE before invoking commands and subtract when finished.
You did not check if all user inputs are valid before invoking the commands.

???

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


0 Me gusta

MRummler
Contributor
Contributor

The thing is that the offset works fine on my autocad i get the 4 lines. the inner lines should be "ld" units from the outer lines while outer lines are "ds"/2 distance from the middle. on my coworkers computer he gets one outer line and one inner line.

 

I was still brand new with lisp when i started this lisp routine, i realized faster ways to make it work, but didn't see a point in changing what already worked.

 

but, I cant figure out why it wont work on his but works on mine. 

 

I will attach a picture of what i mean.

 

 

(update: In picture i labeled the endpoint as pt3, i meant pt2.)

0 Me gusta

BeKirra
Advisor
Advisor

Addition to Scot's comment, I guess your coworker has other codes running without testing your LSP.

Probably (= ds nil) is a false statement on his end.

If this is the case, replace this

(if (= ds nil)
    (setq ds 999)
)

with this

(setq ds 999)

 

HTH 

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 Me gusta

MRummler
Contributor
Contributor

I have the lisp file attached in original message, if you see i also created a reset function which sets DS to nil. I use DS as a global variable to keep the duct size constant as elbows, more straight duct, and reducers are created. That's why i have an if statement where if ds does not equal 999 it starts off asking for pt2 rather than asking for the liner width, sheet matal size, and initial start point... So i don't want to make ds 999 at the start of the function.

0 Me gusta

BeKirra
Advisor
Advisor

Your rotine check if ds = nil when start. It would be fine on your machine.

On your coworker's machine, it could be an issue if a value has already been assigned to ds.

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 Me gusta

MRummler
Contributor
Contributor
Solución aceptada

Which is why i explained to him to use my reset command before starting new duct. It sets DS to nil.

 

I changed the lisp so offset isn't in play, it is now working for him.

Thank you everybody for the help.

0 Me gusta

scot-65
Advisor
Advisor
I stumbled across an older program of mine and saw that
OFFSET can accept an entity (I said earlier that it expects a point).
Apologies for this.

With that, change
(setq ss1 (ssget pt1))
to
(setq ss1 (entlast))

2) If you are going to employ session Gremlins, assign a unique name
that virtually eliminates the possibility of another program overwriting.
'ds' is too easy to overwrite...
I personally name session Gremlins as "USER_" plus "ProgramName".
For your case: "USER_NewLineDuct".

???

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


0 Me gusta