Draw line and array at direction of point picked?

Draw line and array at direction of point picked?

DC-MWA
Collaborator Collaborator
1,337 Views
7 Replies
Message 1 of 8

Draw line and array at direction of point picked?

DC-MWA
Collaborator
Collaborator

I'm hoping somebody has already done this.

I'm tryig to draw a line and then array the line in the direction of a picked point.  It's hard to explain so here is an image.

DC-MWA_0-1606334544526.png

 

Like I said I'm hoping somebody had already created something similar.

0 Likes
Accepted solutions (1)
1,338 Views
7 Replies
Replies (7)
Message 2 of 8

hak_vz
Advisor
Advisor
Accepted solution

Try this

(defun c:copydir ( / vectorSide p1 p2 p3 offset n ss i *error*)
(defun *error* ()
(vla-endundomark (vla-get-ActiveDocument (vlax-get-acad-object)))
(setvar 'cmdecho 1)
(princ)
)
(defun vectorSide (v1 v2 p / r *fuzz*)
(setq r (- (* (-(car v2)(car v1))(-(cadr p)(cadr v1)))
(* (-(cadr v2)(cadr v1))(-(car p)(car v1)))
)
*fuzz* 1e-10
)
(cond ((equal r 0.0 *fuzz*) 0) (t (fix (/ (abs r) r))))
)
(setq p1 (getpoint "\nSelect first point >"))
(setq p2 (getpoint "\nSelect second point >"))
(setq p3 (getpoint "\nPick a point on a side to copy >"))
(setq offset (getreal "\nOffset distance >"))
(setq n (getint "\nNumber of items to create >"))
(princ "\nSelect items to copy >")
(setq ss (ssget))
(vla-endundomark (vla-get-ActiveDocument (vlax-get-acad-object)))
(vla-startundomark (vla-get-ActiveDocument (vlax-get-acad-object)))
(if (>= (vectorSide p1 p2 p3) 1) (setq ang (+ (angle p1 p2) (/ pi 2)))(setq ang (- (angle p1 p2) (/ pi 2))))
(setq i 1)
(setvar 'cmdecho 0)
(while (<= i n)(command "_.copy" ss "" p1 (polar p1 ang (* offset i)) "")(setq i (+ i 1)))
(setvar 'cmdecho 1)
(vla-endundomark (vla-get-ActiveDocument (vlax-get-acad-object)))
(princ)
)

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 3 of 8

DC-MWA
Collaborator
Collaborator

Thank you, this is just what I needed.

0 Likes
Message 4 of 8

Kent1Cooper
Consultant
Consultant

Including the drawing of the Line within it, as I interpreted the request:

(defun C:LMC ; = Line with Multiple offset-style Copies
  (/ offpt offdist offqua end1 end2 base)
  (command "_.line" pause pause "")
  (setq
    offpt (getpoint "\nPick on side to make Copies: ")
    offdist (getdist "\nDistance between Copies: ")
    offqua (getint "\nNumber of Copies: ")
    end1 (vlax-curve-getStartPoint (entlast))
    end2 (vlax-curve-getEndPoint (entlast))
    base
      (polar
        offpt
        (angle
          offpt
          (inters end1 end2 offpt (polar offpt (+ (angle end1 end2) (/ pi 2)) 1) nil)
        ); angle
        offdist
      ); polar & base
  ); setq
  (repeat offqua
    (command "_.copy" (entlast) "" "none" base "_none" offpt)
  ); repeat
  (princ)
); defun
(vl-load-com)

Minimally tested, and it could use the usual enhancements such as Undo begin-end wrapping, and could have others added, such as remembering your spacing and number of copies.

Kent Cooper, AIA
0 Likes
Message 5 of 8

Sea-Haven
Mentor
Mentor

Talks about "ARRAY" a simple method is set Ucs to the line then array will be square to that use UCS 3. Whilst request is for a line can be any object given an angle.

0 Likes
Message 6 of 8

DC-MWA
Collaborator
Collaborator

I'm back in the office.

I'll check it out today. Thank you for your time.

0 Likes
Message 7 of 8

DC-MWA
Collaborator
Collaborator

That's where I started, it got a little confusing with points when you change the ucs mid-way.

0 Likes
Message 8 of 8

Sea-Haven
Mentor
Mentor

Pick pt1 pt2 draw line then pick pt3 do a getclosestpointto then UCS will be 3 points pt1 sqpt pt3, erase line.

 

(setq pt1 (getpoint "\nPoint 1"))
(command "line" pt1 (getpoint pt1 "\nPoint 2") "")
(setq pt3 (getpoint "\Point 3"))
(setq obj (vlax-ename->vla-object (entlast)))
(setq intpt (vlax-curve-getclosestpointto obj pt3))
(command "erase" (entlast) "")
(command "UCS" 3 pt1 intpt pt3)
0 Likes