Small Fish Posted July 12, 2010 Posted July 12, 2010 My test code makes a series of plines. What I would like to know is how would I make each separate pline placed into an entity set while in the while loop? So if there are three pline entities (e1 e2 e3) I can then just use : (command "_.PEDIT" e1 "JOIN" e2 e3"" "") to turn the three plines into a continuous pline. (defun c:testcode (/ pt1 pt2 e1) (setq pt1 (getpoint "\nFirst point: ")) (while pt1 (setq pt2 (getpoint pt1 "\nNext point: ")) (if pt2 (progn (command "_pline" pt1 pt2 "") (setq e1(entlast)) (setq pt1 pt2) );progn (setq pt1 nil) );if );while );defun Quote
CHLUCFENG Posted July 12, 2010 Posted July 12, 2010 Here is a portion of one I did a while back. It gets the points from the user and combines them into one polyline. Also, it calculates the distance as you move along. I needed this to be able to divide the segmants in another portion of the overall code. I hope I don't get chastized too much for the command calls, this I wrote in 2007. (defun WR:GetPoints (/ FirstPoint NextPoint xaaa xbbb yaaa ybbb xdist ydist) (setvar "osmode" 161) (setvar "orthomode" 0) (setq sspolyline nil CalculatedDistance nil) (setq FirstPoint (getpoint "\nPick first point of polyline: "))(terpri) (setq NextPoint (getpoint FirstPoint "\nPick next point of polyline: "))(terpri) (setq LastPoint FirstPoint) (setq xaaa (car LastPoint)) (setq yaaa (cadr LastPoint)) (setq xbbb (car NextPoint)) (setq ybbb (cadr NextPoint)) (if (< xaaa xbbb) (setq xdist (- xbbb xaaa)) (setq xdist (- xaaa xbbb)) ) (if (< yaaa ybbb) (setq ydist (- ybbb yaaa)) (setq ydist (- yaaa ybbb)) ) (setq CalculatedDistance (sqrt (+ (* xdist xdist) (* ydist ydist)))) (command "layer" "M" "E-Temp1" "c" "30" "E-Temp1" "P" "N" "E-Temp1" "S" "E-Temp1" "") (command "pline" LastPoint "w" "1" "1" NextPoint "") (setq poly1 (entlast)) (setq ssPolyline (ssadd)) (ssadd poly1 ssPolyline) (setq polylinePointList (cons LastPoint polylinePointList)) (setq LastPoint NextPoint) (while (setq NextPoint (getpoint LastPoint "\nPick next point of polyline or press <Enter> to end command:")) (terpri) (setq xaaa (car LastPoint)) (setq yaaa (cadr LastPoint)) (setq xbbb (car NextPoint)) (setq ybbb (cadr NextPoint)) (if (< xaaa xbbb) (setq xdist (- xbbb xaaa)) (setq xdist (- xaaa xbbb)) ) (if (< yaaa ybbb) (setq ydist (- ybbb yaaa)) (setq ydist (- yaaa ybbb)) ) (setq AddToCalculatedDistance (sqrt (+ (* xdist xdist) (* ydist ydist)))) (setq CalculatedDistance (+ CalculatedDistance AddToCalculatedDistance)) (command "pline" LastPoint NextPoint "") (setq polynew (entlast)) (command "pedit" "l" "j" polynew ssPolyline "" "") (setq poly1 (entlast)) (ssadd poly1 ssPolyline) (setq polylinePointList (cons LastPoint polylinePointList)) (setq LastPoint NextPoint) );end while (princ) );end WR:GetPoints There are peices in there that may point you in the right direction. Quote
StevJ Posted July 12, 2010 Posted July 12, 2010 I've been using this excellent little routine by lpseifert for a few months now. If any lines selected are not polylines, they are converted before joining. Adjust fuzz distance to suit. ; ; By lpseifert on CADTutor ; http://www.cadtutor.net/forum/showthread.php?t=41420 ; ; Changed FUZZ to 0.00 and a coupla minor comment modifications ; ; WHAT IS DOES -------------------------------------------| ; | ; \|/ ; V (defun c:pj (/ ssj) ;defines the function and declares local variables (setq pa (getvar "peditaccept")) ;stores the existing peditaccept variable setting (setvar "peditaccept" 1) ;sets the peditaccept variable to 1, which suppresses the prompts for ;non-plines, and automatically converts them to plines (setq ssj (ssget )) ;gets and stores your selection (command "PEDIT" "M" ssj "" "J" "0.00" "") ;does PEDIT stuff to what you selected (JOIN with fuzz = 0.00) ;(command "PEDIT" "m" ssj "" "j" "0.00" "s" "") ;<-(use this line if you want to turn it into a spline after joining) (setvar "peditaccept" pa) ;restores peditaccept to what it was (princ) ;clean exit ) ;the end SteveJ Quote
Lee Mac Posted July 13, 2010 Posted July 13, 2010 Perhaps you are looking for something like this? (command "_.pline") (while (= 1 (logand 1 (getvar 'CMDACTIVE))) (command pause) ) Quote
alanjt Posted July 13, 2010 Posted July 13, 2010 Is this all you're wanting? (defun c:Test (/ pt) (if (setq pt (getpoint "\nSpecify first point: ")) (progn (command "_.pline" "_non" pt) (while (> (getvar 'cmdactive) 0) (princ "\nSpecify next point: ") (command PAUSE) ) ) ) (princ) ) Quote
Small Fish Posted July 13, 2010 Author Posted July 13, 2010 Thanks everyone for the replies - Chlucfeng was closest to what I was trying to do. Sorry I was being a bit brief with my code and explanation. Below is what I am trying to do: 1) draw pline 2) break pline 3) insert breakline symbol in break 4) trim lines 5)keep going until enter is pressed (using while loop) this works well up to here... 6) Problem part.....What I am trying to do is turn the 2 broken pline and breakline symbol into a continuous pline using "PEDIT" "JOIN" ... ETC My problem is that I can not identify the 2 halves of the broken pline using "entlast", and then "ssadd" as Chlucfeng suggested in his code. Perhaps one of you guys know of a better way to turn it into a continuous pline? thanks for any replies (defun c:bl2(/ pt1 pt2 pt3 pt4 pt5 pt6 pt7 pt8 x1 x2 ss lk flag sca size ds os ptbrk ang e1 e2 e3 e4 SB_pickpoint SB_next SB_ent SB_proceed SB_next SB_distance SB_entlist SB_closest_point SB_closest_ent SB_newent ) (setq sel1 nil) (setq pt1 (getpoint "\nSpecify first point for breakline: ") pt2 (getpoint pt1 "\nSpecify second point for breakline: ") BrkScale 1.0;temp scale to 1 );setq (command "Pline" pt1 pt2 "") (setq SB_ent (entlast) e2 (entlast) SB_pickpoint T SB_next nil SB_entlist (list SB_ent) );setq (while (setvar "osmode" 512) (setq SB_pickpoint (getpoint (if SB_next "\nSpecify next breakpoint: " "\nSpecify breakpoint: " );if )) (setq SB_proceed T SB_next T SB_distance 1.0e+012 );setq ;;; Find the closest element of all the sub-elements ; (foreach SB_nth SB_entlist (setq SB_obj (vlax-ename->vla-object SB_nth) SB_foundpoint (vlax-curve-getClosestPointTo SB_obj SB_pickpoint nil) );setq (if (< (setq SB_temp (distance SB_pickpoint SB_foundpoint)) SB_distance) (setq SB_distance SB_temp SB_closest_ent SB_nth SB_closest_point SB_foundpoint );setq );if );foreach (command "_break" SB_closest_ent SB_closest_point SB_closest_point) ;;; add the newly created element to the sub-elements ; (setq SB_newent (entlast)) ;;; (setq sel1 (ssadd SB_newent e2)) (if (not (member SB_newent SB_entlist)) (setq SB_entlist (cons SB_newent SB_entlist)) );if (command ".INSERT" "BRKLINE2" SB_closest_point BrkScale;scale "" pt1 pt2 ;angle ) (command ".EXPLODE" "LAST");explode block to pline (setq e3(entlast)) ;;; (setq sel2 (ssadd sel1 e3)) (setq pt4 (polar SB_closest_point (angle pt1 pt2) (* 1.5 BrkScale)) pt4a (polar pt4 (*(angle pt1 pt2)(* 0.5 pi))(* 1.5 BrkScale)) pt4b (polar pt4 (*(angle pt1 pt2)0.5 pi)(* 1.5 BrkScale)) pt5 (polar SB_closest_point (-(angle Pt1 Pt2)(* 1.25 pi))(* 1.5 BrkScale)) pt6 (polar SB_closest_point (+(angle Pt1 Pt2)(* 1.25 pi))(* 1.5 BrkScale)) pt7 (polar SB_closest_point (-(angle Pt2 Pt1)(* 1.25 pi))(* 1.5 BrkScale)) pt8 (polar SB_closest_point (+(angle Pt2 Pt1)(* 1.25 pi))(* 1.5 BrkScale)) );setq (setvar "OSMODE" 0) (command "trim" e3 "" "fence" pt6 pt5 "" "") (command "trim" e3 "" "fence" pt7 pt8 "" "") ;;; (command "_.PEDIT" e3 "JOIN" e1 "" "") );while (princ) );defun BrkLine2.dwg Quote
alanjt Posted July 13, 2010 Posted July 13, 2010 You have the original entity stored, you can access the new one once the original is broken (will be original and new - get with entlast). Here's an ugly example: (defun c:Test (/ p1 p2 e1 mp ss) (if (and (setq p1 (getpoint "\nSpecify first point: ")) (setq p2 (getpoint p1 "\nSpecify next point: ")) ) (progn (command "_.line" "_non" p1 "_non" p2 "") (setq e1 (entlast) mp (mapcar '(lambda (a b) (/ (+ a b) 2.)) p1 p2) ) (command "_.break" e1 "_non" mp "_non" mp) (setq ss (ssadd e1 (ssadd (entlast)))) (if (eq (getvar 'peditaccept) 1) (command "_.pedit" "_m" ss "" "_j" "" "") (command "_.pedit" "_m" ss "" "_y" "_j" "" "") ) ) ) (princ) ) It will draw a line between two picked points, then break at the midpoint and join into a polyline. Quote
Small Fish Posted July 13, 2010 Author Posted July 13, 2010 Hey thanks for the lighting quick reply! yes that's what I am trying to do. I used your line: (setq ss (ssadd e1 (ssadd (entlast)))) It works for just one break but when another break symbol is inserted it hangs up on the line: (setq SB_foundpoint (vlax-curve-getClosestPointTo SB_obj) not sure really why? Quote
alanjt Posted July 13, 2010 Posted July 13, 2010 Because vlax-curve-getClosestPointTo has two requirements. an object (enameor vla-object) a point Quote
CHLUCFENG Posted July 13, 2010 Posted July 13, 2010 You can automatically explode blocks upon insertion with an asterisk '*' before the block name, thus eliminating the need for the EXPLODE command. (command ".INSERT" "*BRKLINE2" SB_closest_point BrkScale ;scale "" pt1 pt2 ;angle ) ; (command ".EXPLODE" "LAST");explode block to pline I am reading your code also to try and get the polylines to join. After the break is finished, and joined, are you supposed to continue a polyline from where the last one left off? Chuck (chlucfeng) Quote
Small Fish Posted July 13, 2010 Author Posted July 13, 2010 Alan Okay I guess that is the problem - object name. After making the first pline and breakline symbol into one entity using pedit, it's name changes. How can I make it so that it accepts the new entity name? Chuck yes I want the user to add in breakline symbols into the original pline until enter is pressed Quote
alanjt Posted July 14, 2010 Posted July 14, 2010 Alan Okay I guess that is the problem - object name. After making the first pline and breakline symbol into one entity using pedit, it's name changes. How can I make it so that it accepts the new entity name? Once you issue PEdit, just use (entlast) to get the 'new' object. Quote
Small Fish Posted July 14, 2010 Author Posted July 14, 2010 Once you issue PEdit, just use (entlast) to get the 'new' object. yes I have already tried that, and I it does not work. If I capture the entity name after pedit then go back to the start of the loop for the second breakline symbol it is looking for a different entity name. Quote
Recommended Posts
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.