Jump to content
pryzmm

Re-draw an object using polyline from nodes created by "divide" command

Recommended Posts

pryzmm

hi, i'm still a beginner in lisp :? and need some help from you guys;

 

;;;----

 

lets say i have a closed polyline outline (shape like a light bulb) that consist of lines and arc as my base entity.

if i were to use "divide" say by "50 segments" (user input) on this polyline can this 50 nodes or more that has been created be use to trace the outline of the entity using "polyline" by lisp.

 

i will then use this newly created closed polyline (all lines) to be the "wipeout" frame as we know that only close "polyline" (all lines) are accepted.

 

i use acad (archi) 2009 (win xp)

 

;;;sequence summary

;;;--------------------------

; prepares the base entity using polyline (lines, arc) before lisp initiation.

 

;(defun c:dw () ; short for divide-wipeout

;(setq oldpdmode (getvar "pdmode"))

;(setq p1 (entsel "\n select entity") ; selection set p1

; ensure that the selection is a polyline otherwise alert the user and re-select.

;(command ".divide" p1 "ask user for input") ; divide command that will ask user on how many segment req.

; use the nodes/points that the ".divide" command created and begin "pline" command to trace those nodes and then close the pline.

; (command "wipeout" "p" entlast "y")

; deletes all the pdmode points

; (princ) exit cleanly

;;;--------------------------

 

 

thank you in advance :)

Share this post


Link to post
Share on other sites
MSasu

Try to parse the polyline parametrically using the required number of vertexes:

 

[color=blue](setq MyPline (vlax-ename->vla-object (entlast))[/color]
[color=blue]      NrNodes 50)[/color]

(setq Param1st   (vlax-curve-getStartParam MyPline)   ;parameter at start point
     Param2nd   (vlax-curve-getEndParam   MyPline)   ;parameter at end point
     ParamLen   (- Param2nd Param1st)                ;parametrical "length"
     DefameSize (/ ParamLen NrNodes))                ;size of defame

(setq theCounter 0)
(command "_PLINE")
(repeat NrNodes
(command (setq thePoint (vlax-curve-getPointAtParam MyPline (+ Param1st (* theCounter DefameSize)))))
(setq theCounter (1+ theCounter))
)
(command "_Close")

 

Regards,

Share this post


Link to post
Share on other sites
Tharwat

This modification close to yours.

(defun c:dw (/ oldpdmode ent )
(setq oldpdmode (getvar "pdmode"))
(setvar "pdmode" 66)
(setq ent (entsel "\n select entity"))
(command "_.divide" ent pause "")
(command "_.wipeout" "_p" ent "y")
 (setvar 'pdmode oldpdmode)
(princ)
)

 

Regards,

 

Tharwat

Share this post


Link to post
Share on other sites
pryzmm

msasu -- thank you for your reply and suggestion, im really a newbie in lisp so your code is like chinese to me,,:unsure: sorry could you explain more please on how to complete it,,

 

tharwat -- thank you as well, my intention was to use the orig. outline as the guide to draw another p-line that will be created or rather traced using the divide command;; you see "wipeout" only accept "closed all lines polyline" (pls. correct me if im wrong) and my idea is by dividing the original outline with enough segment i could somehow mimic the original outline, then use the pline command to connect all the nodes with lines think of it like "connecting dots" but in this case a lisp has to draw that p-line and use the resulting polyline for the "wipeout" command,,,

 

keep on coming guys :)

Share this post


Link to post
Share on other sites
Tharwat

You're welcome.

 

If you want to to select a polyline then divide it into a number and create a polyline to connect all the points that are

created by the divide command, I think it's not possible .

 

Because the points or nodes are do not have a XYZ when they are being made by a command divide, so the polyline or a line

either can't find the coordinate points to connect to.

 

This is what I know about points up to this moment.

 

Thanks

 

Tharwat

Edited by Tharwat

Share this post


Link to post
Share on other sites
pryzmm

@tharwat, thanks once again,, i understand what you mean,, is there any other way i can do it with a similar result if "divide" is not possible?,,, :)

Share this post


Link to post
Share on other sites
MSasu

@pryzmm: My example code is parsing a polyline parametrically and retrace it by a given number of points - it was intended to be added to your code. However I have joined those codes for you:

 

(defun c:PLtoW( / OldOsmode MyPline NrNodes Param1st Param2nd ParamLen DefameSize theCounter )
(vl-load-com)
(setq OldOsmode (getvar "OSMODE"))

(prompt "\nSelect a closed polyline: ")
(while (not (setq MyPline (ssget "_:S" '((0 . "LWPOLYLINE") (70 . 1))))) (princ "\nWrong selection! Try again."))
(if (and MyPline
         (setq NrNodes (getint "\nNumber of vertexes: ")))
 (progn
  (setq MyPline (vlax-ename->vla-object MyPline))

  (setq Param1st   (vlax-curve-getStartParam MyPline)   ;parameter at start point
        Param2nd   (vlax-curve-getEndParam   MyPline)   ;parameter at end point
        ParamLen   (- Param2nd Param1st)                ;parametrical "length"
        DefameSize (/ ParamLen NrNodes))                ;size of defame

  (setq theCounter 0)
  (setvar "OSMODE" 0)
  (command "_PLINE")
  (repeat NrNodes
   (command (setq thePoint (vlax-curve-getPointAtParam MyPline (+ Param1st (* theCounter DefameSize)))))
   (setq theCounter (1+ theCounter))
  )
  (command "_Close")

  (command "_WIPEOUT" "_P" (entlast) "_Y")

  (setvar "OSMODE" OldOsmode)
 )
)
(princ)
)

Regards,

Edited by MSasu
code updated

Share this post


Link to post
Share on other sites
MSasu
If you want to to select a polyline then divide it into a number and create a polyline to connect all the points that are

created by the divide command, I think it's not possible .

 

Because the points or nodes are do not have a XYZ when they are being made by a command divide, so the polyline or a line

either can't find the coordinate points to connect to.

 

In fact is possible to retrace the polyline after marking it with points from DIVIDE command – just need to gather the newly added entities (points) and use their coordinates as arguments for a call of PLINE command.

Also the POINT entity is storing his X, Y and Z coordinates in DXF code 10 no matter the way used to generate it.

 

Regards,

Share this post


Link to post
Share on other sites
pryzmm

msasu,,, exactly my though,, i mean,, i though everything you draw/make in autocad has values no matter what,,,, looks like we can start something from what you've just mentioned,, would you be so kind to help me start on something (lisp) with this idea,,,plsss :cry: -->> thanks

Share this post


Link to post
Share on other sites
MSasu

Did you tested the code in my last (#7) post? It is supposed to do what you asked for. Just load it into AutoCAD and call the new defined PLtoW command. I'm waiting for your feedback.

 

Regards,

Share this post


Link to post
Share on other sites
Tharwat

Hello msasu.

 

Thanks for your clarifications about points.

 

And you did not add the (vl-load-com) to the codes and maybe the user would have a problem without it.

 

one more thing is that the (entlast) would select the last entity have been made recently, and the selected polyline

might not be the last one, so the program would implement the actions at the last entity which may not the

required one, as you know.

 

Thanking you.

 

Tharwat

Share this post


Link to post
Share on other sites
MSasu

@tharwat313: You are right, I missed to add vl-load-com to my code; this is fixed now. Thanks for correction.

 

Regarding the use of entlast, the last added entity to database will be ALWAYS the polyline that is added above (the re-traced one), so is nothing wrong with my code. At least based on my experience.

 

Regards,

Share this post


Link to post
Share on other sites
Tharwat

I tried your codes a lot, and if you select a line instead of a polyline it will continue and implement the points at the selected line.

 

Or if you draw a polyline as a box, and draw a line after that and invoke the command codes it will implement on the line even when

selecting the polyline box also....

 

I am not correcting your codes but just discussing issues.

 

Regards,

 

Tharwat

Share this post


Link to post
Share on other sites
MSasu

I did not pretend that this is an error free code; for sure there is no protection for the entity that is applied on, if is a closed or not polyline and other cases. Is not a commercial application, is solely intended to be used on OP’s issue!

If you want to take care of all exceptions, please fell free to modify it.

 

Regards,

Share this post


Link to post
Share on other sites
pryzmm

hi guys,

 

msasu,,, i tried your code in acad 2008,, and it was amazing exactly what i had in mind, :D only thing i noticed is that the division (spaces between points) are not equally distributed along the entire p-line specially if there are arc, but overall its awesome,,, perhaps an error trap can also be included to prevent the user from selecting another entity beside closed polyline,,, very good indeed --->>> thank you !!! :thumbsup:

 

 

tharwat--thanks man for you feedback,,maybe you can add in a couple of codes to complete it,,, cheers to both of you :thumbsup:

Share this post


Link to post
Share on other sites
MSasu

You're welcome!

 

To get the curve re-traced with equal spaces can use the code below - the polyline is parsed using distances instead of parameters. But this approach can give you ragged results on arc parts.

Have added also a filter for polylines selection only (both in code below and in previous solution).

 

(defun c:PLtoW( / OldOsmode MyPline NrNodes Param1st Param2nd ParamLen DefameSize theCounter )
(vl-load-com)
(setq OldOsmode (getvar "OSMODE"))

(prompt "\nSelect a closed polyline: ")
(while (not (setq MyPline (ssget "_:S" '((0 . "LWPOLYLINE") (70 . 1))))) (princ "\nWrong selection! Try again."))
(if (and MyPline
         (setq NrNodes (getint "\nNumber of vertexes: ")))
 (progn
  (setq MyPline (vlax-ename->vla-object (ssname MyPline 0)))

  (setq Param1st   (vlax-curve-getDistAtParam MyPline (vlax-curve-getStartParam MyPline))   ;distance at start point
        Param2nd   (vlax-curve-getDistAtParam MyPline (vlax-curve-getEndParam   MyPline))   ;distance at end point
        ParamLen   (- Param2nd Param1st)                ;length
        DefameSize (/ ParamLen NrNodes))                ;size of defame

  (setq theCounter 0)
  (setvar "OSMODE" 0)
  (command "_PLINE")
  (repeat NrNodes
   (command (setq thePoint (vlax-curve-getPointAtDist MyPline (+ Param1st (* theCounter DefameSize)))))
   (setq theCounter (1+ theCounter))
  )
  (command "_Close")

  (command "_WIPEOUT" "_P" (entlast) "_Y")

  (setvar "OSMODE" OldOsmode)
 )
)
(princ)
)

Regards,

Edited by MSasu
code updated

Share this post


Link to post
Share on other sites
pryzmm

msasu,,,

 

;your the mannnn ,,, again thank you so much,,

;i have tried it in acad 2009 this time,, everything is smooth and dandee and although it exits right away when you click on an entity other than a polyline could you please see if its possible to add in a few more lines of code so that the user will have another try in picking a p-line until the user hit "esc" to cancel the lisp if he/she did not find any, meaning loop the p-line selection until it finds one or until the user hit "esc" to end it,,,

 

;i promise this will be my last request for this lisp,,,:oops:

 

;overall ---->>>> well done 100/100% :thumbsup:

Share this post


Link to post
Share on other sites
MSasu

@Pryzmm, have modified the above codes as per your request - allows user to try another selection until appropriate entity (closed polyline) is selected.

 

Regards,

Share this post


Link to post
Share on other sites
Lee Mac

Some food for thought, take a look at this superb code by Gile:

http://www.theswamp.org/index.php?topic=28059.0

Share this post


Link to post
Share on other sites
pryzmm

msasu - thanks a millionnnnnnnnnnnnnnnnnnnnnnnnn !!! :)

 

lee mac - thanks for droppin by and for the link -->> will check that up !!! :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×