Hi,
I need to make a lisp routine to draw a mound (mound_2004.dwg), it is saved in 2004 dwg format. Red lines are lines you have and grey lines are lines lisp routine needs to draw.
I have writen some part of lisp (mound.lsp), but have stoped at place where I need to find points on outer line. I wonder if here are some lisp functions to do it ( like this functions: vlax-curve-getPointAtDist, vlax-curve-getClosestPointTo), or I need to make one. I was looking here for functions. But could not found any or could not understand how to use it.
Solved! Go to Solution.
Solved by devitg. Go to Solution.
You can use the vlax-curve-getFirstDeriv obj param
(vlax-curve-getFirstDeriv curve-obj param)
It give the tan as SIN/COS at the point given by PARAM , it return a 3 value list , one is the SIN the other is COS
You have to deal with it , at last you can get the angle perpendicular to the curve at such point
Then you have to make a line , search for it´s intersection points with the outer poliline by IntersectWith
search for more instruction at the VLIDE HELP .
Get the distance between both points , and make the new line related with the wide at such point .
Works, but not finished
(vl-load-com) (setq GDISTANCE 5) (setq GOSNAP_VAR 0) (setq GLAYER 0) (setq GLAYER_NEW "Slaitas") (setq GORTHOMODE 0) (defun da_ChangePropertes ( / ) (setq GOSNAP_VAR (getvar "osmode")) (setq GLAYER (getvar "clayer")) (setq GORTHOMODE (getvar "orthomode")) (setvar "osmode" 0) (command "_layer" "m" GLAYER_NEW "") (setvar "orthomode" 0) ) (defun da_ReturnPropertes ( / ) (setvar "osmode" GOSNAP_VAR) (setvar "clayer" GLAYER) (setvar "orthomode" GORTHOMODE) ) (defun da_FixCoordinates (coords base_pt / first pt0 pt1 pt2 temp_coords) (setq temp_coords (list)) (while (/= coords nil) (setq pt0 (list (car coords) (cadr coords))) (setq coords (cdddr coords)) (setq temp_coords (append temp_coords (list pt0))) ) (list temp_coords) ) (defun da_GetPolylineData (/ polyline_name) (setq polyline_name (car (entsel))) (if (= (cdr (assoc 0 (entget polyline_name))) "LWPOLYLINE") (setq polyline_name polyline_name) (setq polyline_name "0") ) ) (defun da_GetPolyline (msg error_msg / polyline) (setq polyline "0") (while (= polyline "0") (princ msg) (setq polyline (da_GetPolylineData)) (if (= polyline "0") (princ error_msg) (vlax-ename->vla-object polyline) ) ) ) (defun da_GetPointsOnPolyline (ent_name / segment return_data count coord temp_list) (setq coord (vlax-get ent_name 'Coordinates)) (setq count 1) (setq segment 0) (setq return_data (list)) (setq temp_list (list (angle (list (car coord) (cadr coord)) (list (caddr coord) (cadddr coord))))) (setq coord (cddr coord)) (while (/= count nil) (setq segment (+ segment GDISTANCE)) (setq count (vlax-curve-getPointAtDist ent_name segment)) (if (/= count nil) (if (> (vlax-curve-getDistAtPoint ent_name (list (car coord) (cadr coord))) segment) (setq temp_list (append temp_list (list count))) (progn (setq return_data (append return_data (list temp_list))) (setq temp_list (list (angle (list (car coord) (cadr coord)) (list (caddr coord) (cadddr coord))) count)) (setq coord (cddr coord)) ) ) (princ) ) ) (setq return_data (append return_data (list temp_list))) ) (defun da_Intersect (basept angle_in polyline_name / line_name coords) (setq coords (list)) (while (/= basept nil) (command "line" (car basept) (polar (car basept) (- angle_in 1.570796325) 1) "") (setq line_name (entlast)) (command "extend" (vlax-vla-object->ename polyline_name) "" line_name "") (command "extend" (vlax-vla-object->ename polyline_name) "" (list line_name (car basept)) "") (setq coords (append coords (da_FixCoordinates (vlax-invoke polyline_name 'IntersectWith (vlax-ename->vla-object line_name) acExtendNone) (car basept)))) (setq basept (cdr basept)) (command "erase" line_name "") ) (setq coords coords) ) (defun da_FindCoordinatesProc (point1 point2 ac / ab x3 y3) (setq ab (distance point1 point2)) (setq x3 (/ (* (- (car point2) (car point1)) (* ab ac)) ab)) (setq y3 (/ (* (- (cadr point2) (cadr point1)) (* ab ac)) ab)) (list (+ (car point1) x3) (+ (cadr point1) y3)) ) (defun da_DrawLine (coords / line_coords pt1 pt2 faze) (setq faze 1) (while (/= coords nil) (setq line_coords (car coords)) (setq pt1 (car line_coords)) (setq pt2 (cadr line_coords)) (setq coords (cdr coords)) (if (= faze 1) (progn (command "line" (da_FindCoordinatesProc pt1 pt2 0.9) (da_FindCoordinatesProc pt1 pt2 0.1) "") (setq faze 2) ) (progn (command "line" (da_FindCoordinatesProc pt1 pt2 0.7) (da_FindCoordinatesProc pt1 pt2 0.3) "") (setq faze 1) ) ) ) ) (defun C:mound ( / middle_line_name outer_line_name middle_line_coordinates outer_line_coordinates) (setq GLAYER_NEW "Pylimas") (da_ChangePropertes) (setq GDISTANCE (cond ((getint (strcat "\nEnter distance: <" (rtos GDISTANCE 2 0) ">: "))) (GDISTANCE))) (setq middle_line_name (da_GetPolyline "\nSelect middle line. " "\n Error: not polyline.")) (setq outer_line_name (da_GetPolyline "\nSelect outer line. " "\n Error: not polyline.")) (setq middle_line_coordinates (da_GetPointsOnPolyline middle_line_name)) (setq outer_line_coordinates (list)) (while (/= middle_line_coordinates nil) (setq outer_line_coordinates (append outer_line_coordinates (da_Intersect (cdar middle_line_coordinates) (caar middle_line_coordinates) outer_line_name))) (setq middle_line_coordinates (cdr middle_line_coordinates)) ) (da_DrawLine outer_line_coordinates) (da_ReturnPropertes) (princ) ) (prompt "\n Enter \"mound\" to start program.") (princ)
YOU PROGRAM IS THE BEST ALGORITHM & PROGRAM
JUST I CONVERT TO C+ADS
IF YOU NEED CONERT YOUR SOURCE INTO C++ARX OR C# ,PLEASE SEND TO ME THE PRIVATE MESSAGE
AFTER I CONVERTED YOUR SOUCE INTO C+ADS,
THEN I WILL SEE THE SOURCE BEATIFUL IN C#
[CODE]
HERE IT IS YOUR PROGRAME:
(defun da_ChangePropertes ( / rr)
/c2s: GOSNAP_VAR=getvar("osmode"); // HERE IT IS THE PROGRAMMING LANGUAGE" VIRTUAL C+LISP"
GLAYER=getvar("clayer"); // AFTER THE COMPILATION -> RESULT 100% LISP
GORTHOMODE=getvar("orthomode");
setvar("osmode",0);
command("_layer","m",GLAYER_NEW,"");
setvar("orthomode",0);
*/
rr)
(Defun da_DrawLine (coords / line_coords pt1 pt2 faze rr)
/c2s:
faze=1;
while(coords != nil)
{ line_coords=car(coords);
pt1=car(line_coords);
pt2=cadr(line_coords);
coords=cdr(coords);
if (faze == 1)
{ command("line",da_findcoordinatesproc(pt1,pt2,0.9),da_findcoordinatesproc(pt1,pt2,0.1),"");
faze=2;
} ; else
{ command("line",da_findcoordinatesproc(pt1,pt2,0.7),da_findcoordinatesproc(pt1,pt2,0.3),"");
faze=1;
} ;
};
/
rr)
(defun da_FindCoordinatesProc (point1 point2 ac / ab x3 y3 rr)
/c2s: ab=distance(point1,point2);
x3= ( ( (car(point2)-car(point1))* (ab*ac))/ab);
y3= ( ( (cadr(point2)-cadr(point1))* (ab*ac))/ab);
rr=lISt( (car(point1)+x3), (cadr(point1)+y3));
*/
rr)
(defun da_FixCoordinates (coords base_pt / rr first pt0 pt1 pt2 temp_coords)
/c2s: temp_coords=lISt();
while(coords != nil)
{ pt0=lISt(car(coords),cadr(coords));
coords=cadddr(coords);
temp_coords=append(temp_coords,lISt(pt0));
};
rr=lISt(temp_coords);
*/
rr)
(Defun da_GetPointsOnPolyline (ent_name / rr segment return_data count coord temp_list)
/c2s: count=1;
segment=0;
return_data=lISt();
while(count != nil)
{ segment= (segment+GDISTANCE);
count=vlax.curve_getpointatdist(ent_name,segment);
if (count != nil)
return_data=append(return_data,lISt(count));
else terpri();
};
rr=return_data;
*/
rr)
(defun da_GetPolyline (msg error_msg / polyline)
/c2s: polyline="0";
while(_tcscmp(polyline,"0") ==0)
{ princ(msg);
polyline=da_getpolylinedata();
rr=(_tcscmp(polyline,"0") ==0)?princ(error_msg):
vlax_ename2vla_object(polyline) ;
};
*/
rr)
(Defun da_GetPolylineData (/ polyline_name)
/c2s: rr=car(entsel());
if (cdr(assoc(0,entget(rr))) == "LWPOLYLINE")
rr=rr ;
else
rr="0";
*/
rr)
(Defun da_Intersect (basept angle_in polyline_name / line_name coords)
/c2s: coords=lISt();
while(basept != nil)
{ command("line",car(basept),polar(car(basept), (angle_in-1.570796325),1),"");
line_name=entlast();
command("extend",vlax.vla_object->ename(polyline_name),"",line_name,"");
command("extend",vlax.vla_object->ename(polyline_name),"",lISt(line_name,car(basept)),"");
coords=append(coords,da_fixcoordinates(vlax.invoke(polyline_name, "$ 'IntersectWith",vlax.ename->vla_object(line_name),acExtendNone),car(basept)));
basept=cdr(basept);
command("erase",line_name,"");
};
rr=coords;
*/
rr)
(defun da_ReturnPropertes ( / rr)
/c2s: setvar("osmode",GOSNAP_VAR);
setvar("clayer",GLAYER);
setvar("orthomode",GORTHOMODE);
*/
rr)
//ByA: Shinigami_black
%fopen(_pathuser("inc\lspfn_startvar.h"));
(setq GDISTANCE 5)
(setq GOSNAP_VAR 0)
(setq GLAYER 0)
(setq GLAYER_NEW "Slaitas")
(setq GORTHOMODE 0)
%fclose();
(Defun pp_asdk_mound( / rr middle_line_name outer_line_name middle_line_coordinates outer_line_coordinates)
/c2s: dfn_cmd_browser(2);
GLAYER_NEW="Pylimas";
da_changepropertes();
GDISTANCE=cond(getint(strcat("\nEnter distance: <",rtos(GDISTANCE,2,0),">: ")),nil;gdistance);
middle_line_name=da_getpolyline("\nSelect middle line. ","\n Error: not polyline.");
outer_line_name=da_getpolyline("\nSelect outer line. ","\n Error: not polyline.");
middle_line_coordinates=da_getpointsonpolyline(middle_line_name);
outer_line_coordinates=lISt();
while(middle_line_coordinates != nil)
{ outer_line_coordinates=append(outer_line_coordinates,da_intersect(cdar(middle_line_coordinates),caar(middle_line_coordinates),outer_line_name));
middle_line_coordinates=cdr(middle_line_coordinates);
};
da_drawline(outer_line_coordinates);
da_returnpropertes();
terpri();
dfn_cmd_browser(3);
*/
rr)
[/CODE]
Will it increse speend of program?
I programm becouse I want to have more experience in programing and I hate to do manual work, which requires a lot of time and produce little results.