AutoCAD Lisp to Pan a certain, stored distance.

AutoCAD Lisp to Pan a certain, stored distance.

Michael.Traveller
Participant Participant
3,557 Views
21 Replies
Message 1 of 22

AutoCAD Lisp to Pan a certain, stored distance.

Michael.Traveller
Participant
Participant

Hello everyone,

 

I work in HVAC and Pluming design where we have multiple floors, and l always have to pan a certain distance to jump between floors which are separated with a certain distance, "a".

 

Though, l am looking for a lisp which asks me the panning input distance.

 

Any help is greatly appreciated,

 

Thank you!

0 Likes
Accepted solutions (2)
3,558 Views
21 Replies
Replies (21)
Message 2 of 22

ВeekeeCZ
Consultant
Consultant

Change the default vertical distance... 20 is now.

 

(defun c:vpan nil

  (or *vp-dist*
      (setq *vp-dist* 20.))

  (if (setq *vp-dist* (cond ((getdist (strcat "\nSpecify vertical distance <" (rtos *vp-dist*) ">: ")))
			    (*vp-dist*)))
    (command "_.-pan" "_non" (list 0. *vp-dist*) "_non" '(0 0)))
  (princ)
  )

 

Message 3 of 22

Michael.Traveller
Participant
Participant

Hey @ВeekeeCZ ,

 

Thank you so much for this! Can we modify it so we can select if we want to pan up or down, instead of changing the pan distance between + and -?

0 Likes
Message 4 of 22

ВeekeeCZ
Consultant
Consultant
Accepted solution

how about like this

 

(defun c:vup nil
  (or *vp-dist* (c:vset))
  (command "_.-pan" "_non" (list 0. *vp-dist*) "_non" '(0 0))
  (princ)
  )

(defun c:vdo nil
  (or *vp-dist* (c:vset))
  (command "_.-pan" "_non" '(0 0) "_non" (list 0. *vp-dist*))
  (princ)
  )


(defun c:vset nil
  (or *vp-dist* 
      (setq *vp-dist* 20.))
  (setq *vp-dist* (cond ((getdist (strcat "\nSpecify vertical distance <" (rtos *vp-dist*) ">: ")))
			(*vp-dist*)))
  (princ)
  )

 

 
Message 5 of 22

Michael.Traveller
Participant
Participant

that's it, exactly!

 

thank you so much!

0 Likes
Message 6 of 22

Michael.Traveller
Participant
Participant

@ВeekeeCZ Can this be modified to copy immediately something with the required incrementation?

0 Likes
Message 7 of 22

ВeekeeCZ
Consultant
Consultant

Sure, but think about the workflow...

It could either work with this pan command, that you will have an option to Paste copied object at the current position... so you'll be jumping one flor after another.

Or... if the increment match with the floor number, you could just specify a floor number or range of floors...

0 Likes
Message 8 of 22

Michael.Traveller
Participant
Participant

Yes exactly.

 

For example, l need two things to ease my work:

- the first pan lisp which is working perfectly.

- another lisp that lets me select an object, and then copy-paste it to the other floor with the same distance of the floors difference.

 

Example: l need to see where a pipe will end up either in the upper or the lower floor. though l have to copy it from a base point and then select the displacement value. Having a lisp that immediately copy the object based on a set distance will do the trick!

0 Likes
Message 9 of 22

pbejse
Mentor
Mentor

Best that you put those on Tool Palettes.

Click click..

 

0 Likes
Message 10 of 22

ВeekeeCZ
Consultant
Consultant

You're not answering my question. One way or another. Or the third option would be just set GRID to match your increment distance...

 
0 Likes
Message 11 of 22

Michael.Traveller
Participant
Participant

Apologies! 

 

Can l kindly ask to have them both, so l can try and see which one will be more relevant? Thank you tons!

0 Likes
Message 12 of 22

ВeekeeCZ
Consultant
Consultant

Ok, I'll do that sometimes later unless someone else won't step in.

0 Likes
Message 13 of 22

Michael.Traveller
Participant
Participant

thank you so much!

0 Likes
Message 14 of 22

ВeekeeCZ
Consultant
Consultant

@ВeekeeCZ wrote:

... the third option would be just set GRID to (at least Y) match your increment distance...


 

Do you use the GRID? Would you try to set it up manually and test whether it makes the sense to you? Then we could automate it. I can see advantages in this workflow...

 

Z9E3zK5E_0-1630491561694.png

 

0 Likes
Message 15 of 22

Kent1Cooper
Consultant
Consultant

@ВeekeeCZ wrote:

....

Do you use the GRID? ... I can see advantages in this workflow...


So can I, but not with just a GRID setting -- you would also want SNAP turned on:

Kent1Cooper_0-1630494912444.png

 

Kent Cooper, AIA
0 Likes
Message 16 of 22

Michael.Traveller
Participant
Participant

@ВeekeeCZ @Kent1Cooper  It is not so practical as l draw lines within the same plan (floor), so it will be complex.

What l do is copying an object, and manually inserting the distance each time l want to copy something.

 

What could be useful is having a copy up, copy down, copy left, copy right and copy set, same as @ВeekeeCZ second lsp code.

 

And a third one which is also useful would be able to copy and instantly pan to the new location at the same time ( mixing both codes!)

0 Likes
Message 17 of 22

ВeekeeCZ
Consultant
Consultant

heres your 2nd and 3rd. You NEED to PRE-SELECT objects! Then you can repeat the command for how many floors you want.

 

(defun c:cup ( / s)
  (if (and (or (and (ssget "_I")
		    (setq s (ssget "_:L")))
	       (setq s *cup-s*)
	       (setq s (ssget "_:L")))
	   (or *vp-dist* (c:vset))
	   (setq e (entlast))
	   (setq *cup-s* (ssadd))
	   )
    (progn
      (command "_.copy" s "" "_non" '(0 0) "_non" (list 0. *vp-dist*))
      (while (setq e (entnext e))
	(ssadd e *cup-s*))))
  (princ)
  )

(defun c:cvup ( / s)
  (if (and (or (and (ssget "_I")
		    (setq s (ssget "_:L")))
	       (setq s *cup-s*)
	       (setq s (ssget "_:L")))
	   (or *vp-dist* (c:vset))
	   (setq e (entlast))
	   (setq *cup-s* (ssadd))
	   )
    (progn
      (command "_.copy" s "" "_non" '(0 0) "_non" (list 0. *vp-dist*))
      (command "_.-pan" "_non" (list 0. *vp-dist*) "_non" '(0 0))
      (while (setq e (entnext e))
	(ssadd e *cup-s*))))
  (princ)
  )
  

 

0 Likes
Message 18 of 22

Kent1Cooper
Consultant
Consultant
Accepted solution

@Michael.Traveller wrote:

....

What could be useful is having a copy up, copy down, copy left, copy right and copy set....

 

And a third one which is also useful would be able to copy and instantly pan to the new location at the same time ( mixing both codes!)


Here's my take on it.  There are commands for merely Panning in the different directions at the specified distance, for merely Copying, and for Copying and also Panning to the location of the copy.

 

For the Copying ones, you can have object(s) pre-selected or not; it ignores things on locked Layers in either case.

 

I didn't think there was likely to be a single distance common enough to use as a predetermined initial default value, but that can be added easily.  It remembers your distance and offers it as default [only if it exists] so you can see what it was when you go to change it.  Use the getCPdist command to set a new one -- it will be called for you automatically the first time you use any of the commands if there's no distance set yet.

 

I used command names with two C's for the merely-Copy commands, because I already have a custom CL command and I use CR for CiRcle [changing the alias C to be for Copy].  And I used command names with two P's for the merely-Pan commands, because most of the combinations with one are already default aliases.  The Copy-and-Pan-to-the-location-of-the-copy commands start with CP [only one each]

 

(defun C:getCPdist ()
  (initget (if *CPdist 6 7)); no zero, no negative, no Enter on first use
  (setq *CPdist
    (cond
      ( (getdist
          (strcat
            "\nCopy/Pan distance"
            (if *CPdist (strcat " <" (rtos *CPdist) ">") ""); in current Units mode/precision
            ": "
          ); strcat
        ); getdist
      ); User-input condition
      (*CPdist); prior value on Enter [when allowed]
    ); cond
  ); setq
  (princ)
); defun

(defun CDD (dir) ; = Copy at Direction and Distance
  (if (not *CPdist) (C:getCPdist))
  (command "_.copy"
    (cond
      ((ssget "_I") (ssget "_:L-I")); unlocked only among pre-selection if any
      ((ssget "_:L")); otherwise, unlocked only among new selection
    ); cond
    "" "_non" (polar '(0 0) dir *CPdist) ""
  ); command
  (princ)
); defun

(defun C:CCR () (CDD 0)); = Copy Right
(defun C:CCU () (CDD (/ pi 2))); = Copy Up
(defun C:CCL () (CDD pi)); = Copy Left
(defun C:CCD () (CDD (* pi 1.5))); = Copy Down

(defun PDD (dir); = Pan at Direction and Distance
  (command "_.-pan" "_non" (polar '(0 0) dir (- *CPdist)) "")
  (princ)
); defun

(defun C:PPR () (PDD 0)); = Pan Right
(defun C:PPU () (PDD (/ pi 2))); = Pan Up
(defun C:PPL () (PDD pi)); = Pan Left
(defun C:PPD () (PDD (* pi 1.5))); = Pan Down

(defun CPDD (dir); = Copy & Pan at Direction and Distance
  (CDD dir)
  (PDD dir)
  (princ)
); defun

(defun C:CPR () (CPDD 0)); = Copy & Pan Right
(defun C:CPU () (CPDD (/ pi 2))); = Copy & Pan Up
(defun C:CPL () (CPDD pi)); = Copy & Pan Left
(defun C:CPD () (CPDD (* pi 1.5))); = Copy & Pan Down

 

Kent Cooper, AIA
Message 19 of 22

Michael.Traveller
Participant
Participant

Hey!!

 

Apologies for forgetting to thank you!! It is late but l am grateful, you saved me crazy tons of time. This lisp is the best.

 

May l gently ask you if we can add some sort of new functions to it?

1) move something a fixed distance

2) move and pan a fixed distance

3) copy-pattern for multiple distances ( l mean, if l have a block, and l want to copy it from ground floor to F1 to F5, l would like to have a command that copies this block directly to the other floors which are equally distant by me).

 

Thank you so much again!!

0 Likes
Message 20 of 22

Kent1Cooper
Consultant
Consultant

@Michael.Traveller wrote:

....

May l gently ask you if we can add some sort of new functions to it?

1) move something a fixed distance

2) move and pan a fixed distance

3) copy-pattern for multiple distances (... to copy it from ground floor to F1 to F5, ... copies this block directly to the other floors which are equally distant by me).

....


For 1) and 2), it was a simple-enough thing to add Move-oriented versions by editing the Copy-oriented ones -- see the attached CopyMovePanDist.lsp that adds those.  See the notes at the top of the file.  I changed the names of both the get-the-distance command and the global variable that holds that distance, adding the M for Move.

 

It's up to you to check/verify whether you already have any commands or aliases defined that are named the same as any of its command names, and if so, adjust something [you decide what] accordingly.

 

For 3), ARRAY may do what you want, but I also attach something I've used for many years -- CopyAgain.lsp with its CA command.  It has you do a regular Copy operation [with or without pre-selection of objects], and then as many times as you hit Enter/Space, it makes another copy of the selection at the same distance and direction from the previous copy as the initial copy displacement.  Note that [as prompted] you need to hit ESCape [or pick something that includes that, such as a ribbon command icon] to end it -- typing in some other command name while CA's prompt is up will make another copy, rather than get into the command you typed.

Kent Cooper, AIA