Jump to content

LISP to draw Spline or 3D Pline from Points or Lines


Recommended Posts

Posted

I am after a LISP to draw Spline or 3D Pline from Points or Lines as in the attached drawing.

Any help is greatly appreciated. Cheers!

Lines2Spline-.zip

Posted

give this a try:

 

 
(vl-load-com)
;;; to make a 3d polyline*******************************************
(defun c:pol (/ adoc spc ss cnt plst 3dline)
(setq adoc(vla-get-activedocument(vlax-get-acad-object)))
(setq spc(vlax-get adoc
(if (equal (getvar "cvport") 1)
'PaperSpace
'ModelSpace
);_if
)
);_setq
(setq ss (ssget '((0 . "POINT"))));_select only point objects
(if ss
(progn
(setq cnt 0);_loop counter
(setq plst '());_empty list
  (while (< cnt (sslength ss))
(setq plst (cons(cdr(assoc 10(entget (ssname ss cnt))))plst));_make point list
(setq cnt (1+ cnt));_incerase counter
    );_while
(setq 3dline (vla-add3dpoly ;_make 3d polyline 
      spc
      (vlax-safearray-fill
 (vlax-make-safearray vlax-vbDouble
 (cons 0 (1- (length (apply 'append plst)))))
 (apply 'append plst)))
      );_setq add 3dpoly
);_progn
);_if
(princ)
  );_defun
;;; to make a 3d  spline******************************************
(defun c:spl (/ adoc spc ss cnt plst 3dline stpt ept)
(setq adoc(vla-get-activedocument(vlax-get-acad-object)))
(setq spc(vlax-get adoc
(if (equal (getvar "cvport") 1)
'PaperSpace
'ModelSpace
);_if
)
);_setq
(setq ss (ssget '((0 . "POINT"))))
(if ss
(progn
(setq cnt 0);_loop counter
(setq plst '());_empty list
  (while (< cnt (sslength ss))
(setq plst (cons(cdr(assoc 10(entget (ssname ss cnt))))plst))
(setq cnt (1+ cnt));_incerase counter
    );_while
(setq stpt (vlax-3d-point '(0.0 0.0 0.0)));_start pt for spline
(setq ept (vlax-3d-point '(0.0 0.0 0.0)));_end pt for spline
(setq cline (vla-addspline
      spc
      (vlax-safearray-fill
 (vlax-make-safearray vlax-vbDouble
 (cons 0 (1- (length (apply 'append plst)))))
 (apply 'append plst))
      stpt
      ept
      )
      );_setq add 3d spline
);_progn
);_if
(princ)
  );_defun

  • Like 1
Posted

^ JohnM, pardon my stupidity, but how does the program know in which order to follow the points?

Posted

Haven't tried it but looks good.

 

..don't you need a test to see if points are in correct order-depending on how points are created their order in the selection set may not be along the polyline..

 

**oops too slow with the same question :)

Posted

Well you have a good point about the points, so let me point out that you should make it a point to have the points created in the correct order.

You could write a routine that puts them in order but depending on what you are exactly doing it could get very complex and I don’t believe you could cover all the ways it could be calculated.

Posted

Hey Phiphi,

 

If the information can come from a file containing X,Y and Z values have you considered using a script file?

 

For a 3d Poly

;;Turn off osnap
osmode
0
;;start the 3d polyline command
3dpoly
60.8628,72.8892,0.6110
56.3497,70.7362,0.6110
51.8366,68.5842,0.6110
47.3235,66.4322,0.6110
42.9999,63.9422,0.6110
39.4092,60.4812,0.6110
36.7864,56.2392,0.6110
35.2290,51.4962,1.0850
33.9393,46.6652,1.3060
32.6496,41.8352,0.7110
31.3600,37.0042,0.7110
29.6437,32.3202,0.7110
26.8343,28.1992,0.6890
23.0929,24.9022,0.6590
18.6520,22.6332,0.6290
13.7887,21.5262,0.5560
8.8277,20.9022,0.4150
3.8668,20.2782,0.2720
-1.0941,19.6542,0.1450
-6.0551,19.0312,0.0650
-11.0160,18.4072,0.0000

 

For a spline

 

;;Turn off osnap
osmode
0
;;start the 3d polyline command
spline
60.8628,72.8892,0.6110
56.3497,70.7362,0.6110
51.8366,68.5842,0.6110
47.3235,66.4322,0.6110
42.9999,63.9422,0.6110
39.4092,60.4812,0.6110
36.7864,56.2392,0.6110
35.2290,51.4962,1.0850
33.9393,46.6652,1.3060
32.6496,41.8352,0.7110
31.3600,37.0042,0.7110
29.6437,32.3202,0.7110
26.8343,28.1992,0.6890
23.0929,24.9022,0.6590
18.6520,22.6332,0.6290
13.7887,21.5262,0.5560
8.8277,20.9022,0.4150
3.8668,20.2782,0.2720
-1.0941,19.6542,0.1450
-6.0551,19.0312,0.0650
-11.0160,18.4072,0.0000



Posted

Never using a script file, but will learn and try. Thanks you, Jammie. PP.

Posted

helo JohnM

can you improve the lisp to draw 3dpolyline from the file (n x y x) n=number of 3dpolyline x y z three dimension of the point

thanks for your efforts

Posted
Well you have a good point about the points, so let me point out that you should make it a point to have the points created in the correct order
LOL I see what you did there. Didn't really notice it last time.
Posted

i try the script file it is good but not suffecient

you see the lisp submited by johnm it writes coordinates of the 3dpolyline withe a name at first so if you have mor than 3dpoly that mean you have a text file like this for example:

1,-267791.23,160628.28,1139.72

 

1,-267795.60,160626.53,1139.95

 

1,-267799.98,160625.54,1138.60

 

1,-267803.91,160625.17,1135.68

 

1,-267808.80,160625.77,1135.23

 

1,-267813.01,160627.20,1137.30

 

1,-267816.31,160629.19,1140.16

 

2,-267684.33,160614.02,1134.51

 

2,-267689.24,160613.59,1133.70

 

2,-267694.19,160613.32,1133.06

 

2,-267699.17,160613.24,1132.65

 

2,-267704.16,160613.12,1132.34

 

2,-267709.14,160612.82,1132.01

 

2,-267714.12,160612.62,1131.63

 

2,-267719.09,160612.91,1131.18

 

2,-267723.94,160614.02,1130.68

 

2,-267728.69,160615.48,1130.19

 

2,-267733.57,160616.48,1129.78

 

2,-267738.55,160616.49,1129.49

 

2,-267743.48,160615.72,1129.26

 

2,-267748.30,160614.43,1128.99

 

3,-267731.10,160605.46,1130.29

 

3,-267736.04,160604.79,1129.94

 

3,-267740.99,160604.15,1129.58

 

3,-267745.94,160603.53,1129.20

 

3,-267750.89,160602.94,1128.83

 

3,-267755.84,160602.37,1128.45

 

3,-267760.80,160601.84,1128.08

 

3,-267765.76,160601.34,1127.72

 

3,-267770.73,160600.88,1127.38

 

3,-267775.70,160600.46,1127.05

 

3,-267780.68,160600.09,1126.75

 

3,-267785.66,160599.73,1126.49

 

3,-267790.63,160599.25,1126.24

 

3,-267795.57,160598.51,1126.01

 

3,-267800.44,160597.41,1125.80

 

3,-267805.26,160596.11,1125.61

 

the number means 3dpolyline number

so my request to use this file draw 3dpolyline with a number

thanks

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...