Hi,
I need to divide thousands of lines into half, but AutoCAD divide command can only allow you to select one line at a time.Is there any way we can divide multiple lines at once.
Thanks
Do you mean break 1000's of lines into 2 parts or do what the divide command does which is layout points on the lines. If points, I wonder why? There would already be a midpoint to snap to.
i need to insert a mid point on a line. I checked divide command does it but it require to select one by one. I just want is there any way that I can put a point in the middle of all the lines at once rather than selecting each and every line
Not sure I am fully understanding what you're after, so apologies if this is off the mark... If you're only after inserting a point at the mid-point of each Line/LwPolyline selected, consider this:
(vl-load-com) (defun c:PointAtMid (/ *error* ss acDoc oSpace tab) (defun *error* (msg) (if acDoc (vla-endundomark acDoc) ) (cond ((not msg)) ; Normal exit ((member msg '("Function cancelled" "quit / exit abort"))) ; <esc> or (quit) ((princ (strcat "\n** Error: " msg " ** "))) ; Fatal error, display it ) (princ) ) (if (setq ss (ssget '((0 . "LINE,LWPOLYLINE")))) (progn (vla-startundomark (setq acDoc (vla-get-activedocument (vlax-get-acad-object))) ) (setq oSpace (apply (if (setq tileMode (= 1 (getvar 'tilemode))) 'vla-get-modelspace 'vla-get-paperspace ) (list acDoc) ) ) (setq tab (getvar 'ctab)) (vlax-for x (setq ss (vla-get-activeselectionset acDoc)) (vla-addpoint oSpace (vlax-3d-point (vlax-curve-getpointatdist x (* 0.5 (vla-get-length x))) ) ) ) (vla-delete ss) ) (prompt "\n** Nothing selected ** ") ) (*error* nil) )
"How we think determines what we do, and what we do determines what we get."
@Haggoo wrote:i need to insert a mid point on a line. I checked divide command does it but it require to select one by one. I just want is there any way that I can put a point in the middle of all the lines at once rather than selecting each and every line
Not only does it require selecting each and every Line, but it requires recalling the command for each one before you select it [a flaw in the command, in my opinion].
BlackBoxCAD's routine also covers Polylines, putting a Point at the midpoint of the overall length. If you need to do it to Polylines, but want to mark the midpoint of every segment, rather than of the overall length, there's a routine of mine here [MarkMidPoints.lsp and its MMP command] that has that option [as well as lots of other options you wouldn't use for this task]. And it will let you mark as many as you want with one running of the command so you don't need to recall the command for each object, but it still requires you to pick each one, so it won't be useful for large numbers of Lines.
Later, I may try altering it to allow selection of multiple objects at once, but I gotta go....
You didn't answer my question. I don't see how points in the middle of thousands of lines helps anything. Lines already have midpoints that can be snapped to. But attached is a file that will work. Load into autocad with (load "dividelines") at the command line. The code is also embeded:
(vl-load-com) (defun c:dividelines ( / doc spc blk) ;;D. C. Broad, Jr. 4/2013 (setq doc (vla-get-activedocument (vlax-get-acad-object)) spc (vla-get-activespace doc) blk (if (= spc 1) (vla-get-modelspace doc) (vla-get-paperspace doc) ) ) (if (ssget '((0 . "line"))) (progn (vla-startundomark doc) (vlax-for n (vla-get-activeselectionset (setq doc (vla-get-activedocument (vlax-get-acad-object) ) ) ) (vlax-invoke blk 'addpoint (mapcar '(lambda (i j) (/ (+ i j) 2.0)) (vlax-get n 'startpoint) (vlax-get n 'endpoint) ) ) ) ) (vla-endundomark doc) ) (princ) )
It is doing the purpose but I require to select multiple lines at once. Could you please guide me on this.
Thanks
Use a crossing, fence, crossing polygon, or window selection. Sounds like you need to learn how to use AutoCAD. I suggest taking a class.
Haggoo -
More information is needed... What exactly are you trying to do?
Rereading your posts, it sounds like you're wanting to break each line in half, then create a point at the mid-point of each resultant line (which my routine does not do at present)... But then what?
What are you doing with the Points created, or the now broken lines?
"How we think determines what we do, and what we do determines what we get."
@Haggoo wrote:i need to insert a mid point on a line. I checked divide command does it but it require to select one by one. I just want is there any way that I can put a point in the middle of all the lines at once rather than selecting each and every line
(defun C:DL2 (/ cmde ss) ; = apply Divide to all selected Lines at 2 segments each (setq cmde (getvar 'cmdecho)) (setvar 'cmdecho 0) (command "_.undo" "_begin") (setq ss (ssget '((0 . "LINE")))) (repeat (sslength ss) (command "_.divide" (ssname ss 0) 2) (ssdel (ssname ss 0) ss) ); repeat (command "_.undo" "_end") (setvar 'cmdecho cmde) ); defun
You could add a setting of PDMODE and/or PDSIZE to make the Points visible, if that serves any purpose, as well as the usual stuff [error handling, etc.], and perhaps put the Points on the Layers that the Lines are on, and so on.
[This is a situation in which I think the (command) function has a real benefit. The Divide command serves as a very conveniently defined-for-the-purpose sub-routine, which will take care of both the locating of the midpoints of the Lines and the placing of Point entities at them for you, so you don't need to provide code to accomplish those parts. However, it does have the possible disadvantage that it takes longer than (entmake) or (vla-whatever) methods. But whether that's worth worrying about depends on how many Lines you're marking. It took about 4 seconds to do it to 1,000 Lines for me.]
You've now got three programs to accomplish your task. If any of them solve your need please mark the solutions that work for you.
@Patchy wrote:where you see LINE make it LWPOLYLINE
Patchy,
Evaluate Dbroad's routine a bit more closely, as you'd fine that his routine is calulating the midpoint of the Line Object's by calulcating the middle of a given Line Object's Start, and End points, which would preclude his routine from working properly with LwPolyline Object who's line segments are not all parallel.
That is why I instead chose to evaluate the coordinate for the Point Object being added utilizing the vlax-Curve-GetPointAtDist function which properly handles both scenarios.
Cheers
"How we think determines what we do, and what we do determines what we get."
@Haggoo wrote:.... Can you make this file for polylines instead of lines so we can use it for both one for polylines one for lines.
....
For one routine that will work with both Lines and any variety of Polylines [light and heavy, 2D and 3D], you can change this line in my routine:
(setq ss (ssget '((0 . "LINE"))))
to this:
(setq ss (ssget '((0 . "LINE,*POLYLINE"))))
If you would never encounter any Xlines or Splines or Mlines, you could change it to just:
(setq ss (ssget '((0 . "*LINE"))))
It will, as I mentioned before about BlackBoxCAD's routine, put the Points at the midpoint of the overall length of any Polyline, which would be appropriate if they're always single-line-segment Polylines. If you have multi-segment Polylines and you want to mark the midpoint of each segment, elements from the MMP command I linked to before can be incorporated easily enough to do that.
@dbroad3 wrote:
(vl-load-com) (defun c:dividelines ( / doc spc blk) ;;D. C. Broad, Jr. 4/2013 (setq doc (vla-get-activedocument (vlax-get-acad-object)) ) .....
........ (vlax-for n (vla-get-activeselectionset (setq doc (vla-get-activedocument (vlax-get-acad-object) ) ) ) (vlax-invoke ..........
@ dbroad , you have retrieved the document object two times although you use it in the vlax-for funtion which would retrieve the object as much as the quantity of the selection set .
Thanks. That's what comes of rewrites without culling. Thought I'd culled the extra stuff.