Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to select an area, make a copy of it, then select the copy.

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
Huy_Cao
1323 Views, 7 Replies

How to select an area, make a copy of it, then select the copy.

Hi, I am new to Lisp. That's why I met a lot of struggle doing very simple tasks. So please forgive my dummy questions.
Im trying to create a lisp, that do several executions (in a loop) like these things below:
1.  Select an area in the drawings. (always select this area in any turn of the loop)
2. Make a copy of the area in the certain position (this position every loop) . Select the copy.

3. Adjust the copy with datas (datas are different each loop)  (the reason I have to do stage 1 because the copy is changed and is unadjustable after edited)
4. Save dwg file with another name.
5. Delete the copy. End a turn. Come back to 1. 

Thanks to google, I have dealed with 3 and 4 though it takes me a lot of time. But I still struggled with 1 and 2 and 5. So if you have any idea to do that, please give me a hand. Thanks a lot.

7 REPLIES 7
Message 2 of 8
hmsilva
in reply to: Huy_Cao

Hi Huy_Cao

 

as a starting point

1 - Creates a selection set by window, giving two points...

(setq ss (ssget "_W" '(0.0 0.0 0.0) '(100.0 100.0 0.0)))

 2 - starts a new selection set (empty) and set the last object to the variable obj, copy the select objects and add the new objects to the previously empty selection set

    (setq ss1 (ssadd)
	  obj (entlast)
    )
    (command "_.copy" ss "" '(0.0 0.0 0.0) '(200.0 0.0 0.0))
    (while (setq obj (entnext obj))
      (ssadd obj ss1)
    )

 5. Delete the copy

(command "_.erase" ss1 "")

 To create the loop, you can use a 'repeat' or a 'while' function...

 

HTH

Henrique

 

EESignature

Message 3 of 8
alanjt_
in reply to: Huy_Cao

This is a function I use on a daily basis; it should get you the information you need...

 

(defun c:CTC (/ ss)
  ;; Copy selected object(s) to current layer
  ;; Alan J. Thompson
  (if (setq ss (ssget "_:L"))
    ((lambda (layer)
       (vlax-for x (setq ss (vla-get-activeselectionset
                              (cond (*AcadDoc*)
                                    ((setq *AcadDoc* (vla-get-activedocument
                                                       (vlax-get-acad-object)
                                                     )
                                     )
                                    )
                              )
                            )
                   )
         (vla-put-layer (vla-copy x) layer)
       )
       (vla-delete ss)
     )
      (getvar 'clayer)
    )
  )
  (princ)
)
(vl-load-com)
(princ)

 

Message 4 of 8
stevor
in reply to: Huy_Cao

And, before you change anything,

you might use the command UNDO MARK,

to set the begining of the undo seseries.

 

And after the changes made and the dwg saved to a filename,

use UNDO BACK,  to return to that dwg state.

S
Message 5 of 8
Huy_Cao
in reply to: hmsilva

Thank hmsilva, this is exactly what I am looking for!

Message 6 of 8
Huy_Cao
in reply to: stevor

Thank stevor, that's great. I have thought of undo, but because there are many commands so I was not sure about if autocad is able to undo succesfully.
Your idea brings me a new horizon.
Thanks alot.
Message 7 of 8
Huy_Cao
in reply to: alanjt_

Ala, thanks for comment.
But as I said, I have learn about lisp just a little time, so I don't know well about the function?
I have seen such function starting with vla- like yours, but those doesn't work to me. Maybe I need to install some thing, such as a library or....
Could you please tell me how to use those function.
Thank again.
Message 8 of 8
hmsilva
in reply to: Huy_Cao


@Huy_Cao wrote:

Thank hmsilva, this is exactly what I am looking for!


You're welcome, Huy_Cao
Glad I could help

 

Henrique

EESignature

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost