Polyline won't cooperate in a complex LISP routine.

Polyline won't cooperate in a complex LISP routine.

Anonymous
Not applicable
871 Views
3 Replies
Message 1 of 4

Polyline won't cooperate in a complex LISP routine.

Anonymous
Not applicable

This one is a bit of a doozy.  I need the attached LISP routine to place all the entities on spec'd layers in the attached dwg.  I have everything cooperating nicely...except the largest polyline, it will NOT play nice.  I've tried pulling apart all my code and running as separate sections with complete success.  I highly suspect that something in the latter half of the program is overriding the assignments made in the first half, but I can't figure it out.  Can someone help me out here?

 

I've attached the AutoLISP file, and a dwg that shows the block as it starts, what I'm currently getting, and what I need.  Thanks in advance for any help!

 

 

0 Likes
Accepted solutions (2)
872 Views
3 Replies
Replies (3)
Message 2 of 4

dennis
Advisor
Advisor
Accepted solution

Here is what I did:

I took the block and deleted everything except the polyline that is messing up. I found in the code where it is changing the layer:

       (if (and
                    (not (vlax-curve-isclosed b))
                    (and (> (vla-get-length b) 20)(< (vla-get-length b) 5000))
    )
                  ;;the object is NOT closed and has length GREATER THAN 50"
                  (addprop b "HILMOT-FRAMES")
                  ;; then add to this layer
              )

 

Stepping thru the code, it changes it correctly, at that location.  However, just a little below, at:

 

            (setq d (sortlist d > caddr))
            ;;sorting horizontal lines by the length
            (foreach x (setq c (sortlist c > caar))
              (addprop (last x) "HILMOT-ROLLERS")
              ;;moving all other lines to this layer
            )

 

The polyline is still being processed and meets the criteria for the change to the other layer.

 

_1_$ x
((1.02182e-15 1.5) (1.02182e-15 22.5) 507.9 #<VLA-OBJECT IAcadLWPolyline 0000021c0c15bee8>)
_1_$ c
(((1.02182e-15 1.5) (1.02182e-15 22.5) 507.9 #<VLA-OBJECT IAcadLWPolyline 0000021c0c15bee8>))
_1_$ (last x)
#<VLA-OBJECT IAcadLWPolyline 0000021c0c15bee8>

 

Your code implies you should be only processing lines at this point, so maybe an IF Polyline, then don't do.

 

0 Likes
Message 3 of 4

Kent1Cooper
Consultant
Consultant
Accepted solution

@Anonymous wrote:

...except the largest polyline, it will NOT play nice.  ....that something in the latter half of the program is overriding the assignments made in the first half, but I can't figure it out.  Can someone help me out here?

.... 


You seem to have some disagreement in the code:

 

....
                    (and (> (vla-get-length b) 20)(< (vla-get-length b) 5000))
  		)
                  ;;the object is NOT closed and has length GREATER THAN 50"
....

 

But fixing that wouldn't change your problem.

 

I think you're right -- it's getting changed to the Layer you want, and then changed again.  I think it's because this part:

 

              (setq c (cons (list (setz (vlax-curve-getStartPoint b))
                                  (setz (vlax-curve-getEndPoint b))
                                  (vla-get-length b)
                                  b
                            )
                            c
                      )
              )
              ;;creating all point list of all lines

 

is putting every object with its endpoints into that list, regardless of object type [not only lines as described].  In the case of that frame, it probably was put on the FRAMES Layer, but at this point, it's still the 'b' object, and with its start and end points is put into the 'c' list.  It is confirmed as being vertical, because its start and end points do align vertically, so since that appears to be the only criterion, later this:

            (foreach x (setq c (sortlist c > caar))
              (addprop (last x) "HILMOT-ROLLERS")
              ;;moving all other lines to this layer
            )

 

moves it to the ROLLERS Layer.

 

If you have only Line entities put into that 'c' list, or only things less than a certain length, or something, this shouldn't happen.

 

BUT I would suggest a different approach.  Instead of a series of (if) functions looking at characteristics of each 'b' object, use (cond) instead.  With the series of (if)'s, even after it has found the category something belongs in, and has changed it to the appropriate Layer, it still has to go through evaluating it for whether it belongs in any of the other categories, even though it won't.  If you use (cond) instead, it will do what it needs to when it finds the right characteristics, and then it will stop looking at that object, and move on to the next one.  So no object will be processed more than once, as your code is apparently doing.

Kent Cooper, AIA
0 Likes
Message 4 of 4

Anonymous
Not applicable

Thanks very much for the help! Smiley Happy

0 Likes