Jump to content

Pline copy and scale


mousho

Recommended Posts

Hi friends 

i Need help to copy Pline, scale it and draw it in new place

if the long line will align with plan X it be great

i search the web with no success 

 

Screenshot 2022-06-20 094235.png

Link to comment
Share on other sites

I based this on somebody's code that combines a copy with align.  Link in the code.

 

Command SCS (for Copy Scale)

- set scale.

- select polyline.  (if you want it will permit you to select multiple objects)

Then select 3 points (see attached picture)

- point 2 is the source base.

- point 3 is the base point of the destination.

- point 4. that's the end of your long line.  It will be set horizontal on the destination.  The distance of that long line will be used to calculate the scale of the pasted object.

 

;; based on c:COPYALIGN
;; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/combining-copy-amp-align-command/m-p/800575/highlight/true#M26233
;; 
;; Copy SCale
(defun c:CSC (/ sc sSet P11 P12 P21 P22 1st 2nd)
	(setq sc (getreal "\Set scale factor: "))
	;;Combines COPY and ALIGN commands
	;;by Jim Smith 2002
	(or(member "geom3d.arx" (arx))(arxload "geom3d" nil))
	(command "_.undo" "_be")
	(setq sSet (ssget))
	(if sSet
		(progn
			(setq 
				P11 (getpoint "Specify first source point: ")
				P12 (getpoint P11 "\nSpecify first desintation point: ")
				1st (cons 256 (list P11 P12))
			)
			(grvecs 1st)
			(setq 
				P21 (getpoint "\nSpecify second source point: ")
				;; now we calculate P22.  P22 is horizontal to the right of P12.
				;; how much to the right?  distance of P11-P21 X the scale factor
				;; (polar pt ang dist)
				P22 (polar P12 0.0 (* sc (distance P11 P21)))
				2nd (cons 256 (list P21 P22))
			)
			(grvecs 2nd)
			(command "_.COPY" sSet "" "0,0,0" "@")
			(align sSet P11 P12 P21 P22 "" "Y")
		)
	)
	(setq sSet nil)
	(grvecs (list P11 P12))
	(grvecs (list P21 P22))
	(command "_.undo" "_e")
	(princ)
)

 

csc.png

Edited by Emmanuel Delay
  • Like 1
Link to comment
Share on other sites

Came at it a bit different. used entsel as to limit the selection to one entity (assumes if multiple are selected with ssget they will all have different angles)

since limited to one entity selections use while function to allow user to repeat command. like using the copy command with pauses so the user can see the entity moving. like @Steven P did with this.

 

;;----------------------------------------------------------------------------;;
;; Copy, Scale, & Rotate Entity
(defun C:FOO (/ ss pt1 pt2 ang s)
  (while (setq ent (entsel "\nSelect entity: "))
    (setvar 'cmdecho 0)
    (command "_.Undo" "Be")
    (setvar 'cmdecho 1)
    (command ".copy" ent "" pause pause)
    (setvar 'cmdecho 0)
    (setq pt1 (getvar 'lastpoint)
          pt2 (getpoint pt1 "\nHorizontal alignment: ")
          ang (- (angle pt1 pt2))
    )
    (command "_.rotate" (entlast) "" pt1 (* (/ ang pi) 180.0))
    (setq s (getreal "\nScale Factor: "))
    (command "_.scale" (entlast) "" pt1 s)
  )
  (command "_.Undo" "E")
  (setvar 'cmdecho 1)
  (princ)
)

 

  • Like 1
Link to comment
Share on other sites

On 6/20/2022 at 11:59 AM, Emmanuel Delay said:

I based this on somebody's code that combines a copy with align.  Link in the code.

 

Command SCS (for Copy Scale)

- set scale.

- select polyline.  (if you want it will permit you to select multiple objects)

Then select 3 points (see attached picture)

- point 2 is the source base.

- point 3 is the base point of the destination.

- point 4. that's the end of your long line.  It will be set horizontal on the destination.  The distance of that long line will be used to calculate the scale of the pasted object.

 

;; based on c:COPYALIGN
;; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/combining-copy-amp-align-command/m-p/800575/highlight/true#M26233
;; 
;; Copy SCale
(defun c:CSC (/ sc sSet P11 P12 P21 P22 1st 2nd)
	(setq sc (getreal "\Set scale factor: "))
	;;Combines COPY and ALIGN commands
	;;by Jim Smith 2002
	(or(member "geom3d.arx" (arx))(arxload "geom3d" nil))
	(command "_.undo" "_be")
	(setq sSet (ssget))
	(if sSet
		(progn
			(setq 
				P11 (getpoint "Specify first source point: ")
				P12 (getpoint P11 "\nSpecify first desintation point: ")
				1st (cons 256 (list P11 P12))
			)
			(grvecs 1st)
			(setq 
				P21 (getpoint "\nSpecify second source point: ")
				;; now we calculate P22.  P22 is horizontal to the right of P12.
				;; how much to the right?  distance of P11-P21 X the scale factor
				;; (polar pt ang dist)
				P22 (polar P12 0.0 (* sc (distance P11 P21)))
				2nd (cons 256 (list P21 P22))
			)
			(grvecs 2nd)
			(command "_.COPY" sSet "" "0,0,0" "@")
			(align sSet P11 P12 P21 P22 "" "Y")
		)
	)
	(setq sSet nil)
	(grvecs (list P11 P12))
	(grvecs (list P21 P22))
	(command "_.undo" "_e")
	(princ)
)

 

csc.png

thx

work perfect

i did change it a little bit

Quote

;; based on c:COPYALIGN
;; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/combining-copy-amp-align-command/m-p/800575/highlight/true#M26233
;; 
;; Copy SCale
;;Combines COPY and ALIGN commands
;;by Jim Smith 2002
(defun c:CSC     ( / 
                    d dis i m pm p sc sSet se6e P11 P12 P21 P22 1st 2nd leng
                )
    (or    (member "geom3d.arx" (arx))    (arxload "geom3d" nil))
    (command "_.undo" "_be")
    (setq sSet (ssget "+.:E:S" '((0 . "LINE,SPLINE,LWPOLYLINE,POLYLINE,ARC,CIRCLE,ELLIPSE"))))
    (setq se6e (ssname sSet 0))
    (setvar "osmode" 0)
    (setq 
        i 0 
        p 0.0 
        m 0.0
    )
    (while (setq i (1+ i) d (vlax-curve-getdistatparam se6e i))
        (if (< m (setq dis (- d p))) (setq m dis pm (1- i)))
        (setq p d)
    )
        (setq 
            P11 (vlax-curve-getpointatparam se6e pm)    ; Mid Vertex
            P12 (getpoint P11 "\nSpecify first desintation point: ")
;            1st (cons 256 (list P11 P12))
        )
;        (grvecs 1st)
        (setq 
            P21 (vlax-curve-getpointatparam se6e (1+ pm))
                ;; now we calculate P22.  P22 is horizontal to the right of P21.
                ;; how much to the right?  distance of P11-P21 X the scale factor
                ;; (polar pt ang dist)
            sc (/ 100 dis)
            P22 (polar P12 0.0 (* sc (distance P11 P21)))
;            2nd (cons 256 (list P21 P22))
        )
;        (grvecs 2nd)
        (command "_.COPY" sSet "" "0,0,0" "@")
        (align sSet P11 P12 P21 P22 "" "Y")
        (setq sSet nil)
);defun

 

  • Like 1
Link to comment
Share on other sites

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...