access a Lwpolyline from Xref

access a Lwpolyline from Xref

mehsan
Advocate Advocate
1,316 Views
14 Replies
Message 1 of 15

access a Lwpolyline from Xref

mehsan
Advocate
Advocate

hi, how can I access a lwpolyline from Xref file by selection.

thanks

0 Likes
1,317 Views
14 Replies
Replies (14)
Message 2 of 15

Kent1Cooper
Consultant
Consultant

Look into the NCOPY command and/or the (nentsel) AutoLisp function.  Which approach makes the most sense would depend on what you want to do once you access it.

Kent Cooper, AIA
0 Likes
Message 3 of 15

mehsan
Advocate
Advocate

Thanks Dear , actually I want to reach to a point where I can easily select the lwpolyline alone, by Visual Lisp.

thanks

0 Likes
Message 4 of 15

mehsan
Advocate
Advocate

I am using this program but still I need to select the LWpolyline Only , at present it is selecting LWpolyline with markers , stations ETC

thanks

 

 

(defun c:subent ()
  (while  
     (setq Ent (entsel "\nPick an entity: "))
     (print (strcat "Entity handle is: "
          (cdr (assoc 5 (entget (car Ent))))))
   )
   (while  
      (setq Ent (nentsel "\nPick an entity or subEntity: "))
      (print (strcat "Entity or subEntity handle is:  "
          (cdr (assoc 5 (entget (car Ent))))))
   )
  (prompt "\nDone.")
  (princ)
)

 

 

0 Likes
Message 5 of 15

DannyNL
Advisor
Advisor

You will need to check and see with an IF statement if the entity selected is a LWPOLYLINE before continuing with the rest of your code.

 

(defun c:test ()  
   (while  
      (setq Ent (nentsel "\nPick an entity or subEntity: "))
      (if
         (= (cdr (assoc 0 (entget (car Ent)))) "LWPOLYLINE")
         (print (strcat "Entity or subEntity handle is:  " (cdr (assoc 5 (entget (car Ent))))))
         (princ "\n ** Not a LWPOLYLINE!")
      )
   )
)
0 Likes
Message 6 of 15

john.uhden
Mentor
Mentor

You are reminding me of my XOFFSET command function which allows offsetting or cloning of a nested line, arc, circle, ray, xline, or polyline (either a segment or the entire polyline) with a dialog for other choices like layer, color, linetype.

 

As @DannyNL pointed out, you must use nentsel, not entsel.

John F. Uhden

0 Likes
Message 7 of 15

mehsan
Advocate
Advocate

Yes, Can you tell me how you did that.

thanks

0 Likes
Message 8 of 15

Kent1Cooper
Consultant
Consultant

@mehsan wrote:

.... 

(defun c:subent ()
  (while  
     (setq Ent (entsel "\nPick an entity: "))
     (print (strcat "Entity handle is: "
          (cdr (assoc 5 (entget (car Ent))))))
   )
   (while  
      (setq Ent (nentsel "\nPick an entity or subEntity: "))
      (print (strcat "Entity or subEntity handle is:  "
          (cdr (assoc 5 (entget (car Ent))))))
   )
  (prompt "\nDone.")
  (princ)
)


I don't see anything to stop the first (while) loop, which probably means the only way to get out of it is with ESCape, and you therefore would never get to the second (while) loop that uses (nentsel).  Or maybe picking nowhere or hitting Enter stops it, but I'm wondering what you're doing with what it returns -- it doesn't save the handle, or anything.  And if you pick multiple things until Enter or a missed pick, nothing at all is saved about any of them except the last one.

 

I also don't see why the (nentsel) one is in a (while) loop, which also has nothing to end it.  Try something much simpler:

 

(defun c:subent ()
  (setq Ent (nentsel "\nPick an entity or subEntity: "))
  (print

    (strcat

      "Entity or subEntity handle is:  "
      (cdr (assoc 5 (entget (car Ent))))

    )

  )
  (princ)
)

Kent Cooper, AIA
0 Likes
Message 9 of 15

marko_ribar
Advisor
Advisor

That would be fine if user don't miss picking with (nentsel); if he misses your code would error Kent...

Marko Ribar, d.i.a. (graduated engineer of architecture)
0 Likes
Message 10 of 15

DannyNL
Advisor
Advisor

So don't miss and/or build code for the handling of a nil value.

It seems to me that it is very unlikely this code is already finished and I guess it has to do something more than just to return a handle, so error handling is still something to be developed in this case.

0 Likes
Message 11 of 15

john.uhden
Mentor
Mentor

Since I'm not selling anything anymore, should I just give away my XOFFSET?

It doesn't use NCOPY nor copyfrom; it entmakes a new object translated (transformed?) from the nested one.

It works with non-nested entities as well which is neat if you want to offset just one segment of a polyline.

John F. Uhden

0 Likes
Message 12 of 15

Kent1Cooper
Consultant
Consultant

@marko_ribar wrote:

That would be fine if user don't miss picking with (nentsel); if he misses your code would error Kent...


Yes, and @mehsan's in Post 6 would just stop and say "Done" -- kind of meaningless, really, since nothing would be saved from whatever picking of object(s) was done before that point.  There's got to be a lot more to this than we've seen so far.

Kent Cooper, AIA
0 Likes
Message 13 of 15

john.uhden
Mentor
Mentor

(setvar "errno" 0)

(while (/= (getvar "errno") 52)

 ...

)

John F. Uhden

0 Likes
Message 14 of 15

mehsan
Advocate
Advocate

Thanks Every One,

To remove the confusion , Let me explain what is my purpose of this program.

 

I have a stations or chanaige program which is working perfectly all right for Polylines, but if I want to use the same program while polyline is xrefed what will be my basic strategy to select the Polyline, forget if you see stations already marked on my polyline drawing I attached.

thanks   

0 Likes
Message 15 of 15

john.uhden
Mentor
Mentor
I think the easiest solution is putting your chainages in the xref, perhaps
on a unique layer so you can freeze them if you want.

John F. Uhden

0 Likes