TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: V-Man on May 05, 2011, 12:00:05 PM

Title: Check my code
Post by: V-Man on May 05, 2011, 12:00:05 PM

The following code works in 2008 but not in 2010. Any ideas?

Code: [Select]
  (setq ss (ssget "X" '((0 . "LWPOLYLINE")(8 . "0")(70 . 1))));0=Type , 8=Layer Name , 70=lypolylines closed only
(if (= ss nil)
(alert "There are NO LwPolylines!")
)
(if ss
  (repeat (setq n (sslength ss))
    (setq n (1- n))
    (command ".-hatch" "p" "HONEY" "140" "" (ssname ss n) "")
  )
)
Title: Re: Check my code
Post by: Keith™ on May 05, 2011, 12:13:10 PM
I don't have 2010 installed, but the code looks ok ...

Have you tried to step through the code one line at a time?

Where does it specifically fail?
Title: Re: Check my code
Post by: V-Man on May 05, 2011, 12:19:30 PM
Here is what I get when stepping through code.

Quote
Command: (setq ss (ssget "X" '((0 . "LWPOLYLINE")(8 . "0")(70 . 1))))
<Selection set: 69f3>

Command: (repeat (setq n (sslength ss))
(_> (setq n (1- n))
(_> (command ".-hatch" "p" "HONEY" "140" "" (ssname ss n) "")
(_> )

2D point or option keyword required.
; error: Function cancelled

Specify internal point or [Properties/Select objects/draW boundary/remove
Boundaries/Advanced/DRaw order/Origin/ANnotative]: *Cancel*
Title: Re: Check my code
Post by: gile on May 05, 2011, 12:20:07 PM
Hi, maybe some change in the hatch command option.

Look ŕ the the error reported on command line, it's often helpfull to debug issues with the 'command' function...

(command "_.hatch" "HONEY" "140" "" (ssname ss n) "") works with A2011.
Title: Re: Check my code
Post by: Keith™ on May 05, 2011, 12:24:13 PM
That is exactly what I was going to suggest. It looks like "" might need to be changed to "S"

Code: [Select]
(command "_.hatch" "HONEY" "140" "S" (ssname ss n) "")
Title: Re: Check my code
Post by: efernal on May 05, 2011, 12:29:07 PM
I allways use

 (setq ss (ssget "X" '((0 . "LWPOLYLINE")(8 . "0")(-4 . "<OR")(70 . 1)(70 . 129)(-4 . "OR>"))))

because plinegen could be 1 instead 0 when then the polyline was created...
Title: Re: Check my code
Post by: gile on May 05, 2011, 12:46:19 PM
I allways use

 (setq ss (ssget "X" '((0 . "LWPOLYLINE")(8 . "0")(-4 . "<OR")(70 . 1)(70 . 129)(-4 . "OR>"))))

because plinegen could be 1 instead 0 when then the polyline was created...

True, by my side, I'd rather use the "&" operator:

 (setq ss (ssget "X" '((0 . "LWPOLYLINE") (8 . "0") (-4 . "&") (70 . 1))))
Title: Re: Check my code
Post by: V-Man on May 05, 2011, 01:32:27 PM

Thanks to everyone.

The reason I placed a hyphen there in front of the command is for whatever reason, I have 1 machine the code does not work. The code pulls up the hatch dialog box. All other machines the code works fine.

Thanks...
Title: Re: Check my code
Post by: alanjt on May 05, 2011, 01:49:30 PM
If you use -hatch instead of hatch and change your HPSEPARATE variable, you don't have to step through the selectionset.

eg.
Code: [Select]
(defun c:test (/ ov vl ss)
  (setq ov (mapcar 'getvar (setq vl '("CMDECHO" "HPSCALE" "HPNAME" "HPSEPARATE"))))
  (mapcar 'setvar vl '(0 140. "HONEY" 1))
  (if (setq ss (ssget "_X"
                      '((0 . "LWPOLYLINE")
                        (8 . "0")
                        (-4 . "<OR")
                        (70 . 1)
                        (70 . 129)
                        (-4 . "OR>")
                       )
               )
      )
    (command "_.-hatch" "_S" ss "" "_A" "_H" "_Y" "" "")
  )
  (mapcar 'setvar vl ov)
  (princ)
)