Copy and Sum in Y axis

Copy and Sum in Y axis

Francisco_Melo
Enthusiast Enthusiast
1,375 Views
16 Replies
Message 1 of 17

Copy and Sum in Y axis

Francisco_Melo
Enthusiast
Enthusiast

Hello, good morning.
I searched but found nothing, is it possible to copy multiply a block with an attribute and add in relation to the last one the distance between them in relation to the Y axis.
Someone can guide or direct me in the right direction.
Thank you in advance.

0 Likes
Accepted solutions (2)
1,376 Views
16 Replies
Replies (16)
Message 2 of 17

pbejse
Mentor
Mentor

@Francisco_Melo wrote:

Hello, good morning.
I searched but found nothing, is it possible to copy multiply a block with an attribute and add in relation to the last one the distance between them in relation to the Y axis.
Someone can guide or direct me in the right direction.
Thank you in advance.


Starting point for you

 

(defun c:demo  (/ source)
      (if
            (setq source (car (entsel "\nnSelect Block to copy")))
                 (progn
                       (initcommandversion)
                       (command "._copy" source)
                       (while (> (getvar "CMDACTIVE") 0)
                             (command pause)
                             (princ "\nDo your thing here")
                             )
                       )
                 )
      )

 

You think you can pick up from this point onwards @Francisco_Melo ?

 

HTH

 

Message 3 of 17

Francisco_Melo
Enthusiast
Enthusiast

Thanks, by the way
It will be difficult but I will try. Shock will not give.😀

0 Likes
Message 4 of 17

ВeekeeCZ
Consultant
Consultant

Did you try the COPYM command?

Edit: Well, I missed the 'sum' word.

0 Likes
Message 5 of 17

pbejse
Mentor
Mentor

@Francisco_Melo wrote:

Thanks, by the way
It will be difficult but I will try. Shock will not give.😀


Thats the spirit 👍

Post what you come up with, we will guide you from there.

 

 

 

 

 

Message 6 of 17

Sea-Haven
Mentor
Mentor

Need a dwg or image to explain more what you want

0 Likes
Message 7 of 17

Francisco_Melo
Enthusiast
Enthusiast

Hello,
Here is the block. I want to copy and whenever I want to copy and whenever I put the block it adds the distance in Y with the value of the previous one.

0 Likes
Message 8 of 17

ВeekeeCZ
Consultant
Consultant
Accepted solution

Simple version to start with... if you have any questions just ask.

 

(defun c:CopyAltimetric (/ e l y b d p)

  (if (and (setq e (car (entsel "\nSelect 'Altimetric' block: ")))
	   (setq l (entlast))
	   (setq p (cdr (assoc 10 (entget e))))
	   (setq b (getpropertyvalue e "ALT"))
	   (setq d (getvar 'dimzin))
	   (setvar 'dimzin 4)
	   (initcommandversion)
	   (not (command-s "_.copy" e "" "_non" p))
	   )
    (while (setq l (entnext l))
      (if (= "INSERT" (cdr (assoc 0 (entget l))))
	(setpropertyvalue l "ALT" (rtos (/ (+ (* (atof b) 1000) (- (caddr (assoc 10 (entget l))) (cadr p))) 1000) 2 3)))))
  (if d (setvar 'dimzin d))
  (princ)
  )

 

Message 9 of 17

Francisco_Melo
Enthusiast
Enthusiast

Thank you. I was completely lost.

0 Likes
Message 10 of 17

pbejse
Mentor
Mentor
Accepted solution

@Francisco_Melo wrote:

Thank you. I was completely lost.


What happen to trying it out on your own?

Anyway.. hope you learn from this too

 

 

(defun c:demo  (/ source _SetGetvalue _copyl)
(Defun _SetGetvalue  (e v)
	(if v (setpropertyvalue
          e "ALT"
          (Rtos (+ (atof (getpropertyvalue e "ALT"))
                      (* 0.001 v)) 2))
    		(getpropertyvalue e "Position/Y")
	    )
	)
(if  (and
         (princ "\nSelect Block to copy")
         (setq source (ssget "_+.:S:E:L" '((0 . "INSERT")(66 . 1)(2 . "Altimetric"))))         
         (setq p (getpoint "\nSpecify base point:"))
         )
   
    	(progn
       		(setq plus (_SetGetvalue (setq source (ssname source 0)) nil))    
                (while (progn	(prompt "\n[ Press Esc to exit ]")
                                (command "._copy" source "" p pause)
      				(setq p (getvar 'lastpoint))
                             )
				(setq plusThis (_SetGetvalue (setq source (entlast)) nil))
				(_SetGetvalue source (abs (- plus plusThis)))
				(setq plus plusThis))
		)
     	  )
      
(princ)
)

 

 

[ Press Esc to exit ]

HTH

 

Message 11 of 17

pbejse
Mentor
Mentor

@ВeekeeCZ wrote:

Simple version to start with... if you have any questions just ask.

 

(defun c:CopyAltimetric (/ e l y b d p)
...
	   (setq l (entlast))
... (while (setq l (entnext l))
... (princ) )

 


Nice idea. 👍

0 Likes
Message 12 of 17

pbejse
Mentor
Mentor

@Francisco_Melo wrote:

Thank you. I was completely lost.


Where is your attempt? Do you mind if we have a look?

 

0 Likes
Message 13 of 17

Francisco_Melo
Enthusiast
Enthusiast

I'll be honest, I don't understand anything about lisp. I have to take a course to understand, what I'm learning is through comparison of lisp.

 

(defun c:CSY (/ source)
(if
(setq source (car (entsel "\nnSelect Block to copy")))
(progn
(initcommandversion)
(command "._copy" source)
(while (> (getvar "CMDACTIVE") 0)
(command pause)
(getpropertyvalue "ALT")
(command "._copy")
(setpropertyvalue "ALT" (+ Y

)
)
)
)

Message 14 of 17

pbejse
Mentor
Mentor

@Francisco_Melo wrote:

(defun c:CSY (/ source)
...
)


Its a start :), Good for you @Francisco_Melo 

Having seen the codes posted by myself and @ВeekeeCZ ,  Go figure out whats missing and try to complete the code until it works. 🙂

 

Work it, Make it, Do it... 

 

 

 

Message 15 of 17

ВeekeeCZ
Consultant
Consultant

@pbejse wrote:

@ВeekeeCZ wrote:

Simple version to start with... if you have any questions just ask.

 

(defun c:CopyAltimetric (/ e l y b d p)
...
	   (setq l (entlast))
... (while (setq l (entnext l))
... (princ) )

 


Nice idea. 👍


 

Thanks, @pbejse 

Actually, I like yours for changing the values each step... but the ESC exit?! Grrrrrrrrrr!

 

(defun c:CopyAltimetric (/ e b d p)

  (if (and (setq e (car (entsel "\nSelect 'Altimetric' block: ")))
	   (setq b (getpropertyvalue e "ALT"))
	   (setq d (getvar 'dimzin))
	   (setvar 'dimzin 4)
	   )
    (while (progn
	     (setq p (cdr (assoc 10 (entget e))))
	     (initcommandversion)
	     (command "._copy" e "" "_non" p "_non" p)
	     (entdel (entlast))
	     (command pause)
	     (if (> (getvar 'cmdactive) 0)
	       (not (command ""))))
      (setpropertyvalue (setq e (entlast)) "ALT" (setq b (rtos (/ (+ (* (atof b) 1000) (- (caddr (assoc 10 (entget e))) (cadr p))) 1000) 2 3)))))
  (if d (setvar 'dimzin d))
  (princ)
  )

 

Unfortunately, this way is impossible to retrieve the LASTPOINT sysvar, so no other way around than use the insertion point. I like it better this way anyway. 😎

 
Message 16 of 17

pbejse
Mentor
Mentor

@ВeekeeCZ wrote:

 

Thanks, @pbejse 

Actually, I like yours for changing the values each step... but the ESC exit?! Grrrrrrrrrr!

 

th (1).jpg

I just put one together in haste, should've stayed with the original suggestion using (initcommandversion) though.

 

Cheers

 

Message 17 of 17

ВeekeeCZ
Consultant
Consultant

@pbejse wrote:... should've stayed with the original suggestion using (initcommandversion) though.

Cheers


 

Yeah, that's a necessary part of the trick but the real magic, however inefficient, remains, I guess hidden yet unnoticed 😉 No biggie, to be honest, but love how that little trick bends the command to serve to my purpose. 

 

image.png

 

...just like that. Have a great weekend!

0 Likes