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
Solved! Go to Solution.
Solved by Lee_Mac. Go to Solution.
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
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...
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.
+1 kudos for lee keeping it trim
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...
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....
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
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
@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
Good stuff Michael - you're welcome!