View Full Version : HELP WITH DIVIDE LISP PROGRAM
chris.newman0
2011-02-16, 08:20 PM
I will try to explain as best as I can. I'm starting out learning LISP with this program, so as much explanation as you can provide would be great!
The program will divide a line I pick into "X" amount of circles centered on the line, of chosen diameter, once again center point of the circle will be on the picked line. When the program asks how many circles, I would like the circles that are placed at both end points of the line to be included in this quantity.
I don't know if this matters or not, but the lines won't just be in the Y direction, could be X or any angle of line. It would also be nice to be able to pick multiple lines and run the same program instead of copying the circles once their placed for 1 line.
See the attached file.
Here is the simplest way I think the program should run;
-Pick Line.
-Input Diameter of circles.
-Input Number of circles to place on line equally.
That's it!!! Seems easy huh?
Here's as far as I've got....
(defun DIVIDE ()
Ya, that's it, and I'm not sure that's the right define function! The way I read it was, I would run the program, input my preferences for 1 line. Then next time I run the program in the same file, those preferences would be saved, but I would also be able to change for a different quantity or size of circles for another line.
Anyway, if you guy's have some input to help me get started, or any advice would be great!
What this program will serve is for drilling holes on a CNC router for cabinet parts. Currently, i need to choose the line, divide the line w/ divide command, then place circles at each point. It's not hard...but it those boring commands over and over get old.
Thanks a lot!
-Chris Newman
rkmcswain
2011-02-16, 08:39 PM
This may be a good start at what you are aiming for.....
http://cadtips.cadalyst.com/2d-editing/place-blocks-along-multiple-paths
chris.newman0
2011-02-16, 09:08 PM
This may be a good start at what you are aiming for.....
http://cadtips.cadalyst.com/2d-editing/place-blocks-along-multiple-paths
Thanks, I'll have to check out the code and see if I can decipher it. I would prefer not to use blocks, only because our CNC code generator software won't read blocks as machine data, just layer names.
But hopefully it will be more of a start than I have now!
marko_ribar
2011-02-17, 11:09 AM
I hope this satisfies your vision of routine :
(defun c:cirdivcurves ( / DIAM DPT ENT ENTA K L M N NR PT RADIUS SS SS1 X)
(vl-load-com)
(prompt "\nSelect lines or any other open or closed 2d or 3d curve objects")
(setq ss (ssget))
(setq m -1)
(repeat (sslength ss)
(setq m (1+ m))
(setq ss1 (ssadd))
(setq ent (ssname ss m))
(ssadd ent ss1)
(sssetfirst ss1 ss1)
(setq diam (getdist "\nIput diameter of circles (2 points, or number) for selected object : "))
(setq radius (/ diam 2))
(setq n (getint "\nInput how many circles do you want on selected object : "))
(setq nr (atof (itoa n)))
(setq entA (vlax-ename->vla-object ent))
(setq l (vlax-curve-getDistAtParam entA (vlax-curve-getEndParam entA)))
(setq k -1)
(setq x (/ l (- nr 1)))
(repeat (fix nr)
(setq k (+ k 1))
(setq dpt (* k x))
(setq pt (vlax-curve-getPointAtDist entA dpt))
(command "circle" pt radius)
)
)
(princ)
)
Just save code as cirdivcurves.lsp, copy+paste (ctrl+c,ctrl+v) it into CAD interface, and run it by typing :
cirdivcurves at Command :
M.R.
jmcshane
2011-02-17, 11:15 AM
Just pipped at the post by M.R.
Here is my attempt anyway. M.R.'s version is better as it handles curved objects.
(defun c:AddCircles (/ *Activedoc* LineObj Item CircleDia CircleNo CircleDist Startpoint)
(vl-load-com)
(vla-endundomark
(setq *Activedoc* (vla-get-activedocument (vlax-get-acad-object)))
)
(vla-startundomark *Activedoc*)
(if (= (getvar "cvport") 1)
(setq *ActiveSpace* (vla-get-PaperSpace *Activedoc*))
(setq *ActiveSpace* (vla-get-ModelSpace *Activedoc*))
)
(setq CircleDia (getreal "\n Enter Diameter of Circles : ")
CircleNo (getint "\n Enter Number of Circles : ")
)
(while
(setq LineObj (car (entsel "\nSelect Line : ")))
(setq Item (vlax-ename->vla-object LineObj))
(setq Startpoint (vla-get-startpoint Item))
(setq CircleDist (/ (vla-get-length Item) (- CircleNo 1)))
(repeat CircleNo
(vla-addcircle *ActiveSpace* Startpoint (/ CircleDia 2))
(setq Startpoint
(vlax-3D-point
(polar (vlax-safearray->list (vlax-variant-value Startpoint)) (vla-get-angle Item) CircleDist)
)
)
)
)
(vla-endundomark *Activedoc*)
(princ)
)
pbejse
2011-02-17, 01:31 PM
Another way
<Not tested>
(defun c:test (/ objts objt_length strt_pt pts valA)
(vl-load-com)
(defun
Circle (cen rad)
(entmakex
(list (cons 0 "CIRCLE") (cons 10 cen) (cons 40 rad))))
(if (setq objts (car (entsel)))
(progn
(setq CDia (getreal "\nCircle Diameter: ")
CNos (- (getint "\nNumber of Circles: ") 1)
objts
(vlax-ename->vla-object objts)
objt_length
(vlax-curve-getDistAtParam
objts
(vlax-curve-getEndParam objts))
val
(/ objt_length CNos))
(setq valA val)
(circle (vlax-curve-getStartPoint objts) (/ CDia 2))
(repeat Cnos
(circle (vlax-curve-getPointAtDist objts val) (/ CDia 2))
(setq val (+ val valA)))))
(princ))
Works on lines/plines/ellipse/arcs, we will incorporate the default prompt when you decides what routine to use
:)
Hope this helps
chris.newman0
2011-02-17, 02:57 PM
AWESOME! Thanks a lot!! I'll try all these today and get back with you guys!!
-Chris
pbourke
2011-05-26, 10:49 AM
I hope this satisfies your vision of routine :
(defun c:cirdivcurves ( / DIAM DPT ENT ENTA K L M N NR PT RADIUS SS SS1 X)
(vl-load-com)
(prompt "\nSelect lines or any other open or closed 2d or 3d curve objects")
(setq ss (ssget))
(setq m -1)
(repeat (sslength ss)
(setq m (1+ m))
(setq ss1 (ssadd))
(setq ent (ssname ss m))
(ssadd ent ss1)
(sssetfirst ss1 ss1)
(setq diam (getdist "\nIput diameter of circles (2 points, or number) for selected object : "))
(setq radius (/ diam 2))
(setq n (getint "\nInput how many circles do you want on selected object : "))
(setq nr (atof (itoa n)))
(setq entA (vlax-ename->vla-object ent))
(setq l (vlax-curve-getDistAtParam entA (vlax-curve-getEndParam entA)))
(setq k -1)
(setq x (/ l (- nr 1)))
(repeat (fix nr)
(setq k (+ k 1))
(setq dpt (* k x))
(setq pt (vlax-curve-getPointAtDist entA dpt))
(command "circle" pt radius)
)
)
(princ)
)
Just save code as cirdivcurves.lsp, copy+paste (ctrl+c,ctrl+v) it into CAD interface, and run it by typing :
cirdivcurves at Command :
M.R.
Hi Marko
I have found your lisp very useful for drawing road markings so thank you very much.
I was wondering how it could be modified so that the end points of the lines are trimmed by the radius of the circles before the line is divided? This is so the start and endpoint of a line finish with a full circle.
Many thanks
Patrick
Lee Mac
2011-05-26, 11:41 AM
An old one I wrote:
(defun c:test ( / _circle p1 p2 no di an sp i ucsz )
(defun _circle ( center radius )
(entmakex (list (cons 0 "CIRCLE") (cons 10 center) (cons 40 radius) (cons 210 ucsz)))
)
(setq ucsz (trans '(0. 0. 1.) 1 0 t))
(if
(and
(setq p1 (getpoint "\nSpecify First Point: "))
(setq p2 (getpoint "\nSpecify Second Point: " p1))
(progn
(initget 6)
(setq no (getint "\nSpecify Number of Circles: "))
)
(setq di (getdist "\nSpecify Diameter of Circles: "))
)
(progn
(setq p1 (trans p1 1 ucsz) p2 (trans p2 1 ucsz)
an (angle p1 p2) di (/ di 2.)
)
(if (= 1 no)
(setq sp (/ (distance p1 p2) 2.) i 0)
(setq sp (/ (distance p1 p2) (1- no)) i -1)
)
(repeat no (_circle (polar p1 an (* (setq i (1+ i)) sp)) di))
)
)
(princ)
)
pbourke
2011-05-26, 12:02 PM
Thanks Lee, that works pretty similar to Markos.
Could it be modified so that the circle instead of starting from its centre, starts from its quadrant as in the image attached.
Thanks
Patrick
Lee Mac
2011-05-26, 12:05 PM
Certainly Patrick, give this a try:
(defun c:test ( / _circle p1 p2 no di an sp i ucsz )
(defun _circle ( center radius )
(entmakex (list (cons 0 "CIRCLE") (cons 10 center) (cons 40 radius) (cons 210 ucsz)))
)
(setq ucsz (trans '(0. 0. 1.) 1 0 t))
(if
(and
(setq p1 (getpoint "\nSpecify First Point: "))
(setq p2 (getpoint "\nSpecify Second Point: " p1))
(progn
(initget 6)
(setq no (getint "\nSpecify Number of Circles: "))
)
(setq di (getdist "\nSpecify Diameter of Circles: "))
)
(progn
(setq p1 (trans p1 1 ucsz) p2 (trans p2 1 ucsz)
an (angle p1 p2) di (/ di 2.)
p1 (polar p1 an di) p2 (polar p2 an (- di))
)
(if (= 1 no)
(setq sp (/ (distance p1 p2) 2.) i 0)
(setq sp (/ (distance p1 p2) (1- no)) i -1)
)
(repeat no (_circle (polar p1 an (* (setq i (1+ i)) sp)) di))
)
)
(princ)
)
pbourke
2011-05-26, 12:12 PM
perfect. thank you
Lee Mac
2011-05-26, 12:14 PM
You're welcome Patrick ;)
3dwannab
2017-03-22, 01:47 PM
Certainly Patrick, give this a try:
(defun c:test ( / _circle p1 p2 no di an sp i ucsz )
(defun _circle ( center radius )
(entmakex (list (cons 0 "CIRCLE") (cons 10 center) (cons 40 radius) (cons 210 ucsz)))
)
(setq ucsz (trans '(0. 0. 1.) 1 0 t))
(if
(and
(setq p1 (getpoint "\nSpecify First Point: "))
(setq p2 (getpoint "\nSpecify Second Point: " p1))
(progn
(initget 6)
(setq no (getint "\nSpecify Number of Circles: "))
)
(setq di (getdist "\nSpecify Diameter of Circles: "))
)
(progn
(setq p1 (trans p1 1 ucsz) p2 (trans p2 1 ucsz)
an (angle p1 p2) di (/ di 2.)
p1 (polar p1 an di) p2 (polar p2 an (- di))
)
(if (= 1 no)
(setq sp (/ (distance p1 p2) 2.) i 0)
(setq sp (/ (distance p1 p2) (1- no)) i -1)
)
(repeat no (_circle (polar p1 an (* (setq i (1+ i)) sp)) di))
)
)
(princ)
)
Would it be difficult to modify so it can do like attached only pick the line or polyline instead of picking a distance? Thanks.
devitg.89838
2017-03-31, 05:54 PM
It had been 6 years since the post previous to your´s . Could it be possible you upload a dwg sample , and what you have before , and how to show after te lisp???
3dwannab
2017-04-02, 12:34 AM
It had been 6 years since the post previous to your´s . Could it be possible you upload a dwg sample , and what you have before , and how to show after te lisp???
Certainly.
I'd be ever so grateful if you could help with this. I work in interior design quite often and the clients are very particular about EQ spacing of objects.
See drawing attached.
devitg.89838
2017-04-02, 06:03 PM
Hi 3dwanab, would always the objects be a regular shape shape , say 2d , circle, poly, and so on , or there is , say, irregular shapes, if possible upload some samples , not equal to the 3 shown.
If you do not want to upload here , for any reason, you can send it to my email , as at the attached file.
3dwannab
2017-04-03, 12:31 AM
That pretty much it. Those 3 examples are all I will use. I'd rather keep it on the forum in case it's against forum rules.
So. Circles, Squares and blocks. Which I assume could be irregular. But I never have used them.
Just thought it would be good to add that.
So squares and circles will suffice.
devitg.89838
2017-04-03, 01:47 AM
Ok . Let it to be so , Regular shapes .
How many of it it must be at each space?
3dwannab
2017-04-03, 12:19 PM
Like the attached drawing. The object, object count and total distance are the three variables.
If the program could update when typing the array value without exiting the command (double return to accept, I dunno) and printing the spacing distance to the commandline.
Sorry only after thinking that would be nice.
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.