Author Topic: Check my code  (Read 2038 times)

0 Members and 1 Guest are viewing this topic.

V-Man

  • Bull Frog
  • Posts: 343
  • I exist therefore I am! Finally Retired!
Check my code
« 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) "")
  )
)
AutoCAD 9 - 2023, AutoCADMap 2008 - 2010, Revit 2012 - 2022, Autocad Civil 3D 2023

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Check my code
« Reply #1 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?
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

V-Man

  • Bull Frog
  • Posts: 343
  • I exist therefore I am! Finally Retired!
Re: Check my code
« Reply #2 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*
AutoCAD 9 - 2023, AutoCADMap 2008 - 2010, Revit 2012 - 2022, Autocad Civil 3D 2023

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Check my code
« Reply #3 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.
Speaking English as a French Frog

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Check my code
« Reply #4 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) "")
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

efernal

  • Bull Frog
  • Posts: 206
Re: Check my code
« Reply #5 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...
e.fernal

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Check my code
« Reply #6 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))))
Speaking English as a French Frog

V-Man

  • Bull Frog
  • Posts: 343
  • I exist therefore I am! Finally Retired!
Re: Check my code
« Reply #7 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...
AutoCAD 9 - 2023, AutoCADMap 2008 - 2010, Revit 2012 - 2022, Autocad Civil 3D 2023

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Check my code
« Reply #8 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)
)
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox