Jump to content

Recommended Posts

Posted

Lee,

 

thank you again, a perfect explanation!

 

regards

Wolfgang

  • Replies 31
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    14

  • wkplan

    9

  • ollie

    4

  • Rooster

    3

Top Posters In This Topic

Posted

Hi all,

 

i thought it would be a good idea to choose at program-start, which type of LWPoly is checked.

 

Because this is determined mainly in the part of the ssget-function with

  (if (setq ss (ssget "_X" (list '(0 . "LWPOLYLINE")
                               (cons 8 (getvar "CLAYER")) '(70 . 1))))

, wherein (70 . 1) means a closed polyline and (70 . 0) means an open polyline, i believed this could be easy done:

- define a new variable (here "flag")

- let the user make a choice

- parse this variable to the (70 . x)-part of the code

 

Thought that parsing this variable should work exact as the way the current layer is defined in the selection-set, but there is no luck to me.

 

Here is what i have so far:

 

;
; Check for open polylines
; (c) 2009 Lee Mac    
;
(defun c:GetLwClsd (/ ss lay flag)
   (initget 1 "0 1") ; only accept these values as user-input
       (setq flag (getkword "\nLooking for open < 0 > or closed < 1 > LW-Polylines?")); define a variable and let user fill it
   (princ flag) ; just for information, not really needed
;  (if (setq ss (ssget "_X" (list '(0 . "LWPOLYLINE")
;                                 (cons 8 (getvar "CLAYER")) '(70 . 1)))) ; original part of the code
 [color=Blue](if (setq ss (ssget "_X" (list '(0 . "LWPOLYLINE") (cons 8 (getvar "CLAYER")) '(cons 70 (getvar "flag")))))[/color]; and here it fails
                (progn
     (foreach ent (mapcar 'cadr (ssnamex ss))
       (setq lay (tblsearch "LAYER"
                   (cdr (assoc 8 (entget ent)))))
       (if (or (eq 1 (logand 1 (cdr (assoc 70 lay))))
               (eq 4 (logand 4 (cdr (assoc 70 lay)))))
         (ssdel ent ss)))
     (princ (strcat "\n" (itoa (sslength ss)) " found."))
     (sssetfirst nil ss))
   (princ "\n<< nothing found >>"))
 (princ))
(textscr); bring text-window to front and inform user
(princ "\nSearching LW-Polylines at curent layer. Note: splines, curved fit, and 3D plines will not work\nStart with mit << GetLwClsd >>")

Everytime i run it, I can choose the value for "flag" and then it fails.

Where I'm going wrong?

 

Wolfgang

Posted

Take a look at the comments on this code Wolfgang, hopefully it will explain things a bit:

 

 [i][color=#990099];[/color][/i]
 [i][color=#990099]; Check for open polylines[/color][/i]
 [i][color=#990099]; (c) 2009 Lee Mac    [/color][/i]
 [i][color=#990099];[/color][/i]
[b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] c:GetLwClsd  [b][color=RED]([/color][/b][b][color=BLUE]/[/color][/b] ss[b][color=RED])[/color][/b] [i][color=#990099]; Notice that *flag_def* is not localised, as it is a global variable[/color][/i]
 
 [b][color=RED]([/color][/b][b][color=BLUE]or[/color][/b] *flag_def* [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] *flag_def* [b][color=#ff00ff]"Open"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [i][color=#990099];; Set first-time default[/color][/i]
 
 [b][color=RED]([/color][/b][b][color=BLUE]initget[/color][/b] [b][color=#ff00ff]"Open Closed"[/color][/b][b][color=RED])[/color][/b] [i][color=#990099]; Only allow these values, allow enter also[/color][/i]
 
 [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] *flag_def*
   [b][color=RED]([/color][/b][b][color=BLUE]cond[/color][/b] [b][color=RED]([/color][/b][b][color=RED]([/color][/b][b][color=BLUE]getkword[/color][/b]
            [b][color=RED]([/color][/b][b][color=BLUE]strcat[/color][/b] [b][color=#ff00ff]"\nLooking for [O]pen or [C]losed LWPolylines? <"[/color][/b] *flag_def* [b][color=#ff00ff]"> : "[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
         [i][color=#990099];; Either a keyword has been entered, hence set it as the new default[/color][/i]
         
         [b][color=RED]([/color][/b][b][color=BLUE]t[/color][/b] *flag_def*[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [i][color=#990099];; Else use the original default[/color][/i]
 
 [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] ss
       [b][color=RED]([/color][/b][b][color=BLUE]ssget[/color][/b] [b][color=#ff00ff]"_X"[/color][/b]
         [b][color=RED]([/color][/b][b][color=BLUE]list[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]0[/color][/b] [b][color=#ff00ff]"LWPOLYLINE"[/color][/b][b][color=RED])[/color][/b]
               [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]8[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]getvar[/color][/b] [b][color=#ff00ff]"CLAYER"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
               [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]70[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]cond[/color][/b] [b][color=RED]([/color][/b][b][color=RED]([/color][/b][b][color=BLUE]eq[/color][/b] *flag_def* [b][color=#ff00ff]"Open"[/color][/b][b][color=RED])[/color][/b] [b][color=#009900]0[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]t[/color][/b] [b][color=#009900]1[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
                               [i][color=#990099];; If *flag_def* is "Open" use 0, else use 1.[/color][/i]
   
   [b][color=RED]([/color][/b][b][color=BLUE]progn[/color][/b]
     [b][color=RED]([/color][/b][b][color=BLUE]foreach[/color][/b] ent  [b][color=RED]([/color][/b][b][color=BLUE]mapcar[/color][/b] [b][color=DARKRED]'[/color][/b][b][color=BLUE]cadr[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]ssnamex[/color][/b] ss[b][color=RED])[/color][/b][b][color=RED])[/color][/b]
       [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] lay [b][color=RED]([/color][/b][b][color=BLUE]tblsearch[/color][/b] [b][color=#ff00ff]"LAYER"[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]cdr[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]assoc[/color][/b] [b][color=#009900]8[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]entget[/color][/b] ent[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
       [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]or[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]eq[/color][/b] [b][color=#009900]1[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]logand[/color][/b] [b][color=#009900]1[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]cdr[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]assoc[/color][/b] [b][color=#009900]70[/color][/b] lay[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
               [b][color=RED]([/color][/b][b][color=BLUE]eq[/color][/b] [b][color=#009900]4[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]logand[/color][/b] [b][color=#009900]4[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]cdr[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]assoc[/color][/b] [b][color=#009900]70[/color][/b] lay[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
         [b][color=RED]([/color][/b][b][color=BLUE]ssdel[/color][/b] ent ss[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
     [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]strcat[/color][/b] [b][color=#ff00ff]"\n"[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]itoa[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]sslength[/color][/b] ss[b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=#ff00ff]" found."[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
     [b][color=RED]([/color][/b][b][color=BLUE]sssetfirst[/color][/b] [b][color=BLUE]nil[/color][/b] ss[b][color=RED])[/color][/b][b][color=RED])[/color][/b]
   [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b] [b][color=#ff00ff]"\n<< nothing found >>"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
 [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
[b][color=RED]([/color][/b][b][color=BLUE]textscr[/color][/b][b][color=RED])[/color][/b] [i][color=#990099]; bring text-window to front and inform user[/color][/i]
[b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b] [b][color=#ff00ff]"\nSearching LW-Polylines at curent layer.
         Note: splines, curved fit, and 3D plines
         will not work\nStart with mit << GetLwClsd >>"[/color][/b][b][color=RED])[/color][/b]

Posted

Lee,

 

this is perfect!

Thankyou.

 

I have to read carefull youre code, but with these excellent comments :)

 

Didn't know the initget-function, but now i should be able to use this in similiar cases.

 

Still far away from writing my own code, just tweek stolen code a little bit.

 

Regards

Wolfgang

Posted

this is perfect!

Thankyou.

 

I have to read carefull youre code, but with these excellent comments :)

 

Not a problem Wolfgang, happy to help.

 

Didn't know the initget-function, but now i should be able to use this in similiar cases.

 

The Initget is a useful function, not only for getkword but for all the "getXXX" functions and"entsel" also. Read up on the bit arguments for more.

 

Still far away from writing my own code, just tweek stolen code a little bit.

 

Don't worry, you can learn a lot from other peoples code, and its only practice after all. :)

 

 

If you have any further questions, just ask.

 

Regards,

 

Lee

Posted

Hello Lee,

 

at the first look anythings is great.

 

I tested the routine with a larger drawing, which contains ~300 polylines, all of them are closed. (Checked in property window and hatched them, all is fine. But the drawing was done by different people).

 

GetLwClsd failed in correct count, I wondered why.

 

Reading the documentation, I noticed that the groupcode 70 can hold three bits (for LWPolylines only, Polylines are more complex):

0 = polyline is open (default)

1 = polyline is closed

128 = plinegen is used

 

This means, there are 4 combinations possible:

0 = open polyline, plinegen not used

1 = closed polyline, plinegen not used

128 = open polyline, plinegen is used

129 = closed polyline, plinegen is used

 

Looked some closer at the not counted polylines, I noticed they are different: property "use linetype" is activated :o, and there's the reason, because plinegen leads straight to this property.

 

How will a filter-statement look, that checks for:

a) ( 70 . 0 ) or ( 70 . 128 ) if I will look for open polylines, and

b) ( 70 . 1 ) or ( 70 . 129 ) if I will count closed polylines?

 

Another method would be some kind of brute force, just collect all polylines and change the groupcode, but this looks to me a little destructive.

 

regards

Wolfgang

Posted

How about this:

 

 [i][color=#990099];[/color][/i]
 [i][color=#990099]; Check for open polylines[/color][/i]
 [i][color=#990099]; (c) 2009 Lee Mac    [/color][/i]
 [i][color=#990099];[/color][/i]
[b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] c:GetLwClsd  [b][color=RED]([/color][/b][b][color=BLUE]/[/color][/b] ss[b][color=RED])[/color][/b] [i][color=#990099]; Notice that *flag_def* is not localised, as it is a global variable[/color][/i]
 
 [b][color=RED]([/color][/b][b][color=BLUE]or[/color][/b] *flag_def* [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] *flag_def* [b][color=#ff00ff]"Open"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [i][color=#990099];; Set first-time default[/color][/i]
 
 [b][color=RED]([/color][/b][b][color=BLUE]initget[/color][/b] [b][color=#ff00ff]"Open Closed"[/color][/b][b][color=RED])[/color][/b] [i][color=#990099]; Only allow these values, allow enter also[/color][/i]
 
 [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] *flag_def*
   [b][color=RED]([/color][/b][b][color=BLUE]cond[/color][/b] [b][color=RED]([/color][/b][b][color=RED]([/color][/b][b][color=BLUE]getkword[/color][/b]
            [b][color=RED]([/color][/b][b][color=BLUE]strcat[/color][/b] [b][color=#ff00ff]"\nLooking for [O]pen or [C]losed LWPolylines? <"[/color][/b] *flag_def* [b][color=#ff00ff]"> : "[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
         [i][color=#990099];; Either a keyword has been entered, hence set it as the new default[/color][/i]
         
         [b][color=RED]([/color][/b][b][color=BLUE]t[/color][/b] *flag_def*[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [i][color=#990099];; Else use the original default[/color][/i]
 
 [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] ss
       [b][color=RED]([/color][/b][b][color=BLUE]ssget[/color][/b] [b][color=#ff00ff]"_X"[/color][/b]
         [b][color=RED]([/color][/b][b][color=BLUE]list[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]0[/color][/b] [b][color=#ff00ff]"LWPOLYLINE"[/color][/b][b][color=RED])[/color][/b]
               [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]8[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]getvar[/color][/b] [b][color=#ff00ff]"CLAYER"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
               [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]-4[/color][/b] [b][color=#ff00ff]"<OR"[/color][/b][b][color=RED])[/color][/b]
               [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]70[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]cond[/color][/b] [b][color=RED]([/color][/b][b][color=RED]([/color][/b][b][color=BLUE]eq[/color][/b] *flag_def* [b][color=#ff00ff]"Open"[/color][/b][b][color=RED])[/color][/b] [b][color=#009900]0[/color][/b][b][color=RED])[/color][/b]   [b][color=RED]([/color][/b][b][color=BLUE]t[/color][/b] [b][color=#009900]1[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
               [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]70[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]cond[/color][/b] [b][color=RED]([/color][/b][b][color=RED]([/color][/b][b][color=BLUE]eq[/color][/b] *flag_def* [b][color=#ff00ff]"Open"[/color][/b][b][color=RED])[/color][/b] [b][color=#009900]128[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]t[/color][/b] [b][color=#009900]129[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
               [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]-4[/color][/b] [b][color=#ff00ff]"OR>"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
   
   [b][color=RED]([/color][/b][b][color=BLUE]progn[/color][/b]
     [b][color=RED]([/color][/b][b][color=BLUE]foreach[/color][/b] ent  [b][color=RED]([/color][/b][b][color=BLUE]mapcar[/color][/b] [b][color=DARKRED]'[/color][/b][b][color=BLUE]cadr[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]ssnamex[/color][/b] ss[b][color=RED])[/color][/b][b][color=RED])[/color][/b]
       [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] lay [b][color=RED]([/color][/b][b][color=BLUE]tblsearch[/color][/b] [b][color=#ff00ff]"LAYER"[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]cdr[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]assoc[/color][/b] [b][color=#009900]8[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]entget[/color][/b] ent[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
       [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]or[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]eq[/color][/b] [b][color=#009900]1[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]logand[/color][/b] [b][color=#009900]1[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]cdr[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]assoc[/color][/b] [b][color=#009900]70[/color][/b] lay[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
               [b][color=RED]([/color][/b][b][color=BLUE]eq[/color][/b] [b][color=#009900]4[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]logand[/color][/b] [b][color=#009900]4[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]cdr[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]assoc[/color][/b] [b][color=#009900]70[/color][/b] lay[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
         [b][color=RED]([/color][/b][b][color=BLUE]ssdel[/color][/b] ent ss[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
     [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]strcat[/color][/b] [b][color=#ff00ff]"\n"[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]itoa[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]sslength[/color][/b] ss[b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=#ff00ff]" found."[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
     [b][color=RED]([/color][/b][b][color=BLUE]sssetfirst[/color][/b] [b][color=BLUE]nil[/color][/b] ss[b][color=RED])[/color][/b][b][color=RED])[/color][/b]
   [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b] [b][color=#ff00ff]"\n<< nothing found >>"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
 [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
[b][color=RED]([/color][/b][b][color=BLUE]textscr[/color][/b][b][color=RED])[/color][/b] [i][color=#990099]; bring text-window to front and inform user[/color][/i]
[b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b] [b][color=#ff00ff]"\nSearching LW-Polylines at curent layer.
         Note: splines, curved fit, and 3D plines
         will not work\nStart with mit << GetLwClsd >>"[/color][/b][b][color=RED])[/color][/b]

Posted

Lee,

thanks again!

 

What started as some kind of interessting stuff, leaded now to a verry usefull function, which I believe other people will find it usefull too.

 

I learned a lot, maybee more in one day reading youre excellent postings, than reading 14 days lisp-documentation.

(I knew, there is plenty of good lisp-docu around, and I have to read as many as I can...)

 

Kind regards

Wolfgang

Posted

I'm glad I could help out.

 

Documentation is good, but there is no-one that you can ask if you get stuck - thats what I like about the forums :)

 

Lee

  • 7 years later...
Posted

Hi LeeMac,

 

i found this post in google. i need small extension in your great code. i need close all poly lines in my drawing and any layer poly lines automatically. is this possible?

 

Thanks.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...