ronjonp Posted August 12, 2009 Posted August 12, 2009 See if this helps (defun getobjlayoutname (obj /) (cond ((= (type obj) 'ename) (cdr (assoc 410 (entget obj)))) ((= (type obj) 'vla-object) (cdr (assoc 410 (entget (vlax-vla-object->ename obj))))) ) ) (setq layname (getobjlayoutname (car (entsel)))) (setq layobj (vla-item (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))layname)) Quote
SteveK Posted August 12, 2009 Author Posted August 12, 2009 Hey Ron, thanks. That's a good work-a-round, I'll use it. And I did not know about the type function; that's helpful. It's strange get-layout doesn't work though it turns up blue in the vlisp editor don't you think? Quote
Lee Mac Posted August 12, 2009 Posted August 12, 2009 Another method: (defun getlayout (Obj) (vla-get-Name (vla-get-layout (vla-objectidtoobject (vla-get-ActiveDocument (vlax-get-acad-object)) (vla-get-ownerid Obj))))) Quote
Lee Mac Posted August 12, 2009 Posted August 12, 2009 It's strange get-layout doesn't work though it turns up blue in the vlisp editor don't you think? Not really. Objects don't have the layout property. Check the propertys of an object using vlax-dump-object Quote
SteveK Posted August 12, 2009 Author Posted August 12, 2009 Thanks Lee. That's a good way of staying with a vla-object. Not really. Objects don't have the layout property.Check the propertys of an object using vlax-dump-object Yeah but that's whats strange. vla-objects seem to carry lots more information than entities yet it doesn't carry the layout it's on whereas entities do. That said your method does include vla-get-layout which indicates it is stored somewhere and vlax-dump-object is more just "surface" information...? Quote
Lee Mac Posted August 12, 2009 Posted August 12, 2009 When objects are drawn they are defined within a block - whether that be the ModelSpace/PaperSpace blocks, or definition within an AutoCAD block definition. (I think we've already had a convo about these blocks), and so, the owner of the object is the block in which it is defined. So I have retrieved the owner id, converted it back to a VLA-Object (block), which has the layout property. Lee Quote
SteveK Posted August 13, 2009 Author Posted August 13, 2009 Thanks for explaining mate. Sorry you have to explain things so many times. When it's the same problem from a different angle sometimes it's hard to see that it's the same answer. Quote
Lee Mac Posted August 13, 2009 Posted August 13, 2009 No worries, I am happy to explain - just tying all the knowledge together Quote
ronjonp Posted August 13, 2009 Posted August 13, 2009 Another method: (defun getlayout (Obj) (vla-get-Name (vla-get-layout (vla-objectidtoobject (vla-get-ActiveDocument (vlax-get-acad-object)) (vla-get-ownerid Obj))))) Nice....... (the dots are for the 10 character limit) Quote
Lee Mac Posted August 13, 2009 Posted August 13, 2009 Nice....... (the dots are for the 10 character limit) Thanks Ron Quote
SteveK Posted September 8, 2009 Author Posted September 8, 2009 Hey guys, Just another quick question relating to layouts; how do I get the paperspace object if I have the layout/tab name? Quote
Lee Mac Posted September 8, 2009 Posted September 8, 2009 Two ways: Either using the vla-item function within a function to catch exceptions: (defun get_item (i col / item) (if (not (vl-catch-all-error-p (setq item (vl-catch-all-apply 'vla-item (list col i))))) item)) (defun c:test ( ) (get_item "Layout1" (vla-get-layouts (vla-get-ActiveDocument (vlax-get-acad-object))))) Or, just by cycling through the collection itself: (defun c:test (/ result) (vlax-for lay (vla-get-layouts (vla-get-activeDocument (vlax-get-acad-object))) (if (eq "Layout1" (vla-get-Name lay)) (setq result lay))) result) Quote
SteveK Posted September 8, 2009 Author Posted September 8, 2009 Lee, I'm having some trouble using it. For my current task, I want to insert a block on a specified layout. This I currently do by finding an object on the specified layout and getting the paperspace object (code you helped me with somewhere else): (setq [color=Blue][b]pspc[/b][/color] (vla-objectidtoobject (vla-get-activedocument (vlax-get-acad-object)) (vla-get-ownerid <object on Layout1>))) (setq blk (vla-insertblock [color=Blue][b]pspc[/b][/color] (vlax-3d-point '(0.0 0.0 0.0)) "New Block" 1 1 1 0 ) ) I was hoping to substitute the pspc variable with what you've given me: ; Get Layout Paperspace Object (defun layoutObj (layName / result) (vlax-for lay (vla-get-layouts (vla-get-activeDocument (vlax-get-acad-object))) (if (eq layName (vla-get-Name lay)) (setq result lay))) result) (setq [b][color=Blue]pspc[/color][/b] (layoutObj "Layout1")) (setq blk (vla-insertblock [color=Blue][b]pspc[/b][/color] (vlax-3d-point '(0.0 0.0 0.0)) "New Block" 1 1 1 0 ) ) But this doesn't work. Is there another step to get it as a paperspace object? Quote
ronjonp Posted September 8, 2009 Posted September 8, 2009 Try this instead: (setq pspc (vla-get-block (layoutobj "Layout1"))) Quote
SteveK Posted September 8, 2009 Author Posted September 8, 2009 Thanks Ron that did it! (You wouldn't think it would reading the helpfile on vla-get-block though - Specifies block of MLeaderStyle? ) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.