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

copy tab from other drawing with contents

12 REPLIES 12
SOLVED
Reply
Message 1 of 13
idragonb
1378 Views, 12 Replies

copy tab from other drawing with contents

Hello all,

 

I am programming in lisp and I have copied a tab from a template file into the current file - I used

 

(vlax-get-property layout 'Name)                              ; from template

(vlax-invoke-method layouts 'Add layname)              ; to current drawing

(vlax-invoke-method nlayout 'CopyFrom layout)        ; copies properties (I think)

 

and now I would like to copy the border and any other objects in that tab but I'm stumped.....

 

The items are in the 'Block property of the layout but a simple put-property does not work - what am I missing?

 

Any suggestions?

 

Thanks,

Michael

Flow state:
Maximum challenge with maximum skills.
Tags (3)
12 REPLIES 12
Message 2 of 13
Lee_Mac
in reply to: idragonb

As per my response to your email, attached is a function to copy a specified layout tab from another drawing into the current drawing; posted here for the benefit of the community.

 

Aside, if you intend to post your question to the forums, I would appreciate if you did not email me the same question directly. Granted, perhaps I am too generous with my time and should only respond to paid enquiries in future, referring all other questions to the forums.

 

Lee

Message 3 of 13
idragonb
in reply to: Lee_Mac

Hi,

Yes you are generous and I was fairly certain that the answer would come
from you so I addressed you directly. In the future I will post on the
forum first and lacking a response, will turn to you directly. As you
initially replied that you would answer when you had a moment, I thought
that it might take more than just an hour, so I reposted in the forum...
You are very prompt and I appreciate the help.

Michael
Flow state:
Maximum challenge with maximum skills.
Message 4 of 13
idragonb
in reply to: Lee_Mac

This is the line that I am trying to understand:

 

(vlax-invoke dbx 'copyobjects (reverse lst) (vla-get-block tar))

 

I understand that:

- dbx is the active document

- copyobjects is the method invoked

- lst is a list of all objects in the Block property of the source layout

- which are being copied into the Block property of the target layout

 

Question:

Is my understanding correct?

Why do you need to reverse the list?

 

perhaps I am missing something because I am getting an error when I apply this to my code

 

; error: lisp value has no coercion to VARIANT with this type:  (#<VLA-OBJECT IAcadBlockReference 000000003bee5628> #<VLA-OBJECT IAcadPViewport 000000002f4c7208>)

 

My list does in fact contain the layout objects.

 

(defun import_tab ();(dwgname) ; enter manually for debug
(setq acad (vlax-get-acad-object))
(setq doc (vlax-get-property acad 'ActiveDocument)) ; dwg to insert into
(setq docs (vlax-get-property acad 'Documents))
(setq doc-template (vlax-invoke-method docs 'Open (strcat TPA_PATH "\\" dwgname)))
(setq template-layouts (vlax-get-property doc-template 'Layouts))                                                 ; allows to choose from list of tabs
(setq count (vlax-get-property template-layouts 'Count))
(setq nn 0)
(while (< nn count)
(setq layout (vlax-invoke-method template-layouts 'Item nn))
(setq layname (vlax-get-property layout 'Name))
(princ (strcat (itoa (1+ nn)) ") " layname "\n"))
(setq nn (1+ nn))
)
(graphscr)
(setq choice (1- (getint "\nChoose layout: ")))                                                          ; has chosen tab
(setq layout (vlax-invoke-method template-layouts 'Item choice)) ;source
(setq layname (vlax-get-property layout 'Name))
(setq layouts (vlax-get-property doc 'Layouts))
(setq nlayout (vlax-invoke-method layouts 'Add layname)) ;target
(vlax-invoke-method nlayout 'CopyFrom layout)
(setq lblk (vlax-get-property layout 'Block)) ;source
(setq layout-content (vlax-get-property nlayout 'Block)) ; target


(vlax-for obj (vla-get-block lblk) (setq lst (cons obj lst)))    ;  problem here...
(vlax-invoke-method doc 'CopyObjects lst layout-content)
)

 

Any help appreciated...

Flow state:
Maximum challenge with maximum skills.
Message 5 of 13
Lee_Mac
in reply to: idragonb


idragonb wrote:

This is the line that I am trying to understand:

 

(vlax-invoke dbx 'copyobjects (reverse lst) (vla-get-block tar))

 

I understand that:

- dbx is the active document

- copyobjects is the method invoked

- lst is a list of all objects in the Block property of the source layout

- which are being copied into the Block property of the target layout

 

Question:

Is my understanding correct?


No, the dbx variable is the ObjectDBX document of the source drawing.

Other than that, yes - your understanding is correct.


idragonb wrote:

Why do you need to reverse the list?


Because the list is constructed in reverse within the vlax-for loop, and the objects must be in order to ensure that the paperspace viewport is constructed correctly in the target layout.


idragonb wrote:

perhaps I am missing something because I am getting an error when I apply this to my code

 

; error: lisp value has no coercion to VARIANT with this type:  (#<VLA-OBJECT IAcadBlockReference 000000003bee5628> #<VLA-OBJECT IAcadPViewport 000000002f4c7208>)


vlax-invoke-method requires a safearray variant of type vlax-vbobject, whereas vlax-invoke allows a list to be supplied.

Message 6 of 13
bhull1985
in reply to: Lee_Mac

+1 kudos for lee keeping it trim

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Please use code tags and credit where credit is due. Accept as solution, if solved. Let's keep it trim people!
Message 7 of 13
idragonb
in reply to: bhull1985

Lee is an awesome programmer - succinct and robust. I have learned a lot from what he shares on the web and also individual responses.

 

I am a little stubborn I confess, I am still trying to understand the flaw in my logic...

Flow state:
Maximum challenge with maximum skills.
Message 8 of 13
bhull1985
in reply to: idragonb

Oh don't worry. He has an interesting way of keeping people in line, and believe me, you're not the only one who has learned a thing or two from him that wasn't via a code-post on one of the multiple forums.

Which, by the way if you're needing more excellent resources, here's the ones myself and many others view frequently.

 

Cadtutor forums:

http://www.cadtutor.net/forum/forumdisplay.php?21-AutoLISP-Visual-LISP-amp-DCL

 

Augi forums:

http://forums.augi.com/forumdisplay.php?91-AutoLISP

 

TheSwamp forums:

http://www.theswamp.org/index.php?board=2.0

 

and of course the one we're viewing now. I'll tell a quick story, when I first started posting, I had send Lee an email as well, hoping to get some help in my first program. He is a busy man and as such it took until the next day to receive a response via email, and I had taken the liberty of posting the code Lee had supplied , modified heavily and incorrectly by me of course in my novice days, which i'm still in.....IMO, but anyways, so I post the code and ask for others help. Lee replies to my email and then comes to the thread and basically slams me for not crediting him and let's just say....I learned from then on that credit to code originators is important. Just one of the many things he's shown me...so, take it personally....but keep in mind he's not having it out for you. Just..."keeping it trim" IMO 😄

Now, riff-raff aside, did you have further questions about the code in the earlier posts? Perhaps we can learn something more....

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Please use code tags and credit where credit is due. Accept as solution, if solved. Let's keep it trim people!
Message 9 of 13
idragonb
in reply to: Lee_Mac

http://www.theswamp.org/index.php?topic=39365.0

 

My understanding was limited as I was not familiar with dbx. Above link discusses it (thanks again Lee) and the Lisp Bible goes into greater detail.

 

Cheers!

 

Michael

Flow state:
Maximum challenge with maximum skills.
Message 10 of 13
idragonb
in reply to: bhull1985

Yeah, the Swamp rat is my other favorite.

 

The code I posted is actually what I came up with, I just got stuck on the object porting.

 

I always credit Lee and if you look in my tags, you will see that I also put him there 🙂

 

I've been at this a while too, but still consider myself a beginner... (15+ years)

 

While we are at giving credit, I definitely need to acknowledge openDcl. Awesome work...

 

Cheers

Flow state:
Maximum challenge with maximum skills.
Message 11 of 13
Lee_Mac
in reply to: idragonb


@idragonb wrote:

Lee is an awesome programmer - succinct and robust. I have learned a lot from what he shares on the web and also individual responses.

 

I am a little stubborn I confess, I am still trying to understand the flaw in my logic...


Thank you for your compliments Michael, I'm glad that my contributions are of benefit to your learning.

 

Do you now understand the operations performed by the function?

 

Lee

Message 12 of 13
idragonb
in reply to: Lee_Mac

Hi Lee,

Yes. Finally after cracking my skull all day I found that I just forgot to initialize my object array. The working on closed drawings is a new skill that I was happy to stumble upon, thanks for that - I did a little routine that pulls the layouts from a closed drawing and inserts into current as the user chooses.

Need to work on my error checking skills, but I'll get to that eventually.

Thanks for the support!

Michael
Flow state:
Maximum challenge with maximum skills.
Message 13 of 13
Lee_Mac
in reply to: idragonb

Good stuff Michael - you're welcome!

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

Post to forums  

Autodesk Design & Make Report

”Boost