View Full Version : Re-draw an object using polyline from nodes created by "divide" command
pryzmm
28th Jul 2010, 06:05 am
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 :)
MSasu
28th Jul 2010, 06:35 am
Try to parse the polyline parametrically using the required number of vertexes:
(setq MyPline (vlax-ename->vla-object (entlast))
NrNodes 50)
(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,
Tharwat
28th Jul 2010, 10:22 am
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
pryzmm
28th Jul 2010, 12:36 pm
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 :)
Tharwat
28th Jul 2010, 12:52 pm
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
pryzmm
28th Jul 2010, 03:09 pm
@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?,,, :)
MSasu
28th Jul 2010, 08:24 pm
@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,
MSasu
28th Jul 2010, 08:30 pm
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,
pryzmm
29th Jul 2010, 06:48 am
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
MSasu
29th Jul 2010, 07:06 am
Did you tested the code in my last (#7 (http://www.cadtutor.net/forum/showthread.php?50838-Re-draw-an-object-using-polyline-from-nodes-created-by-quot-divide-quot-command&p=345294&viewfull=1#post345294)) post? It is supposed to do what you asked for. Just load (http://www.cadtutor.net/faq/questions/28/How+do+I+use+an+AutoLISP+routine%3F) it into AutoCAD and call the new defined PLtoW command. I'm waiting for your feedback.
Regards,
Tharwat
29th Jul 2010, 07:26 am
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
MSasu
29th Jul 2010, 07:41 am
@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,
Tharwat
29th Jul 2010, 07:53 am
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
MSasu
29th Jul 2010, 08:45 am
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,
pryzmm
29th Jul 2010, 03:43 pm
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:
MSasu
29th Jul 2010, 07:48 pm
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,
pryzmm
30th Jul 2010, 06:04 am
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:
MSasu
31st Jul 2010, 07:54 pm
@Pryzmm, have modified the above codes as per your request - allows user to try another selection until appropriate entity (closed polyline) is selected.
Regards,
Lee Mac
31st Jul 2010, 08:48 pm
Some food for thought, take a look at this superb code by Gile:
http://www.theswamp.org/index.php?topic=28059.0 (http://www.theswamp.org/index.php?topic=28059.0)
pryzmm
2nd Aug 2010, 05:47 am
msasu - thanks a millionnnnnnnnnnnnnnnnnnnnnnnnn !!! :)
lee mac - thanks for droppin by and for the link -->> will check that up !!! :)
MSasu
2nd Aug 2010, 10:40 am
msasu - thanks a millionnnnnnnnnnnnnnnnnnnnnnnnn !!! :)
You're welcome!
Regards,
pryzmm
21st Aug 2010, 05:12 am
hi again guys,
i do not want to start another thread so i dig up my old one that is where it all started.
msasu had compile an excellent routine (see below) i have tested it several times in acad 2008 and 2009 (arch't) in a totally clean drawing environment (no drawing at all except the p-line i was testing the routine with) which execute perfectly, everything is smooth.
then i have added a few lines of code just to use my preferred "layer" in doing the wipeout, and when i tested it at my office work (messy drawings - cad 2009),, it just went through up to the end of the routine without any thing done, no errors too,,,,
im sure there must be something in the code that i messed up,, could anyone take a look,, im not too familiar with lisp just yet.
appreciate any help :)
code start here;;;
;
;created by: msasu 31-08-2010
;lwpolyline to wipeout routine
;
;
(defun c:PL2WO ( / OldOsmode MyPline NrNodes Param1st Param2nd ParamLen DefameSize theCounter )
(vl-load-com)
(setq OldOsmode (getvar "OSMODE"))
;;--
(setq oldlayer (getvar "clayer"))
;;--
(if (and (setq MyPline (car (entsel "\nSelect polyline: ")))
(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")
;------------------------------- added code
(if (tblsearch "layer" "SF_FP-WIPEOUT")
(command ".-layer" "set" "SF_FP-WIPEOUT" "")
(progn
(setq rgn (getvar "regenmode")) (setvar "regenmode"0)
;;--
(command ".-layer" "make" "SF_FP-WIPEOUT" "color" "254" "ltype" "m-dot" "" "")
(setvar "regenmode" rgn)
);progn
);if
;------------------------------- end of added code
(command "_WIPEOUT" "_P" (entlast) "_Y")
;restore orig variables
;;--
(setvar "clayer" oldlayer)
;;--
(setvar "OSMODE" OldOsmode)
)
)
(princ)
)
;;; also if you guys need to know the full story behind this lisp pls. feel free to read page 1,2-->> thxxx
Powered by vBulletin™ Version 4.1.2 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.