Jump to content

Replacing blocks across multiple layouts


SteveK

Recommended Posts

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))

Link to comment
Share on other sites

  • Replies 36
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    16

  • SteveK

    16

  • ronjonp

    3

  • Patrick_35

    2

Top Posters In This Topic

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?

Link to comment
Share on other sites

Another method:

 

(defun getlayout (Obj)
 (vla-get-Name
   (vla-get-layout
     (vla-objectidtoobject
       (vla-get-ActiveDocument
         (vlax-get-acad-object))
           (vla-get-ownerid Obj)))))

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

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...?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.:unsure:

Link to comment
Share on other sites

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):lol:

Link to comment
Share on other sites

  • 4 weeks later...

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)

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...