TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: ronjonp on May 08, 2013, 11:32:07 AM

Title: Rename Paperspace Layout OBDX
Post by: ronjonp on May 08, 2013, 11:32:07 AM
Has anyone figured out how to do this or is it just a limitation? I can see the layout object and all the properties ... but when I try and delete or rename, this error is thrown:

Quote
Error: Automation Error. Layout does not eixst for renaming; reset after error
  ... and yes "exist" is misspelled  :-)
Title: Re: Rename Paperspace Layout OBDX
Post by: ronjonp on May 08, 2013, 01:07:25 PM
Maybe some code to test...

Code - Auto/Visual Lisp: [Select]
  1. (defun c:test (/ odbx v)
  2.   (if (setq
  3.         odbx (if (< (atoi (setq v (substr (getvar 'acadver) 1 2))) 16)
  4.                (vla-getinterfaceobject (vlax-get-acad-object) "ObjectDBX.AxDbDocument")
  5.                (vla-getinterfaceobject (vlax-get-acad-object) (strcat "ObjectDBX.AxDbDocument." v))
  6.              )
  7.       )
  8.              odbx
  9.              (strcat (getvar 'dwgprefix) (vl-filename-base (getvar 'dwgname)) "-test.dwg")
  10.            )
  11.            ;; This is where the poo happens :)=
  12.            (vlax-for l (vla-get-layouts odbx)
  13.              ;; Rename first tab in new drawing to tabname from old drawing
  14.              (and (= (vla-get-taborder l) 1) (vla-put-name l "test"))
  15.              ;; Delete the second tab "Layout2"
  16.              ;; (and (= (vla-get-taborder l) 2) (vla-delete l))
  17.            )
  18.            (vlax-release-object odbx)
  19.     )
  20.   )
  21. )
Title: Re: Rename Paperspace Layout OBDX
Post by: Lee Mac on May 08, 2013, 01:46:16 PM
Using your supplied code, the first layout in the active drawing was renamed, not that of the saved drawing.  :?
Title: Re: Rename Paperspace Layout OBDX
Post by: kruuger on May 08, 2013, 01:53:24 PM
Has anyone figured out how to do this or is it just a limitation? I can see the layout object and all the properties ... but when I try and delete or rename, this error is thrown:

Quote
Error: Automation Error. Layout does not eixst for renaming; reset after error
  ... and yes "exist" is misspelled  :)
same error on 2010
k.
Title: Re: Rename Paperspace Layout OBDX
Post by: ronjonp on May 08, 2013, 02:01:47 PM
Using your supplied code, the first layout in the active drawing was renamed, not that of the saved drawing.  :?

No errors?
Title: Re: Rename Paperspace Layout OBDX
Post by: BlackBox on May 08, 2013, 02:15:25 PM
Using your supplied code, the first layout in the active drawing was renamed, not that of the saved drawing.  :?

Perhaps, for testing purposes, it would be better to instead vl-File-Copy the Active Document first, and then open the resultant Drawing via DBX, being sure to save the changes afterward.  :-)
Title: Re: Rename Paperspace Layout OBDX
Post by: kruuger on May 08, 2013, 02:22:10 PM
Using your supplied code, the first layout in the active drawing was renamed, not that of the saved drawing.  :?

No errors?
no. code rename layout in active dwg.
i used this for test:
Code: [Select]
(defun 000:GetDbxDocument ()
  (vla-getInterfaceObject (vlax-get-acad-object)
    (strcat "ObjectDBX.AxDbDocument." (substr (getvar "ACADVER") 1 2) )
  )
)
(not
  (vl-catch-all-error-p
    (vl-catch-all-apply
      (quote vla-open)
      (list
        (setq dbx (000:GetDbxDocument))
        "d:\\xxx.dwg"
      )
    )
  )
)
(setq *cd-Layouts* (vla-get-layouts dbx))
(vlax-for % *cd-Layouts*
  (vla-delete (vla-item *cd-Layouts* "1-01"))
)
(vlax-release-object Dbx)
dwg xxx.dwg on d: with layout 1-01
k.
Title: Re: Rename Paperspace Layout OBDX
Post by: Cathy on May 08, 2013, 02:25:53 PM
It ran for me in 2012, renaming Layout1 tab to test in the active drawing. 

(and (= (vla-get-taborder l) 1) (vla-put-name l "test"))

Just for my education, why do you use "and" here?  I would have used "if".  Does the vla-put-name run even if the first half is nil? 
Title: Re: Rename Paperspace Layout OBDX
Post by: BlackBox on May 08, 2013, 02:36:07 PM
(and (= (vla-get-taborder l) 1) (vla-put-name l "test"))

Just for my education, why do you use "and" here?  I would have used "if".  Does the vla-put-name run even if the first half is nil?

No... When the first expression returns Nil, the second expression is not evaluated.
Title: Re: Rename Paperspace Layout OBDX
Post by: BlackBox on May 08, 2013, 02:45:35 PM
Has anyone figured out how to do this or is it just a limitation? I can see the layout object and all the properties ... but when I try and delete or rename, this error is thrown:

Even after accounting for the renaming of the active document, I too am receiving the same typo... err, I mean error message.

I also tried accessing the Layout Object with vla-Item (in case renaming an iterated object was the cause for the error), but this too was unsuccessful for me... Tested in Civil 3D 2011, and 2012.
Title: Re: Rename Paperspace Layout OBDX
Post by: ronjonp on May 08, 2013, 03:25:19 PM
Thanks for checking this. Guess it's just a bug.
Title: Re: Rename Paperspace Layout OBDX
Post by: Marc'Antonio Alessi on May 08, 2013, 03:47:18 PM
Same here in 2010:  :o
Code: [Select]
(defun ALE_Utl_GetItem (VlaCol KeyNam / VlaObj)
  (vl-catch-all-apply
   '(lambda ( )
      (setq VlaObj (vla-item VlaCol KeyNam))
    )
  )
  VlaObj
)
(setq
  DbxDoc (vla-GetInterfaceObject
  (vlax-get-Acad-Object) (strcat "ObjectDBX.AxDbDocument." (substr (getvar "ACADVER") 1 2)))
)
(vl-catch-all-error-p (vl-catch-all-apply 'vla-Open (list DbxDoc "test.dwg")))


(vlax-dump-object  (setq lllll (vla-get-Layouts DbxDoc)) T)
; IAcadLayout:
...
;   Document (RO) = #<VLA-OBJECT IAxDbDocument 000000000cc22fa0>
>>> different >>> Document IAxDb
...


(vlax-dump-object  (setq aaaaa (vla-get-Layouts (vla-get-activedocument (vlax-get-acad-object)))) T)
; IAcadLayout:
...
on (RO) = #<VLA-OBJECT IAcadApplication 00000001409f6c70>
;   Document (RO) = #<VLA-OBJECT IAcadDocument 000000000cae3bc0>
>>> different >>> Document IAcad
...

(setq LayObj    (ALE_Utl_GetItem aaaaa "Layout1"))
(setq LayODBX (ALE_Utl_GetItem lllll "Layout1"))


(vla-put-name LayObj "test") or (vla-put-name LayODBX "test")
>>> rename always Layout1 on active DWG
Title: Re: Rename Paperspace Layout OBDX
Post by: BlackBox on May 08, 2013, 03:52:00 PM
Thanks for checking this. Guess it's just a bug.

You're welcome, ronjonp... Short of a Script, or investigating if a .NET LispFunction Method could perform this task within a LISP's ObjectDBX wrapper, I'm not sure how else to accomplish this.

Good luck :beer:
Title: Re: Rename Paperspace Layout OBDX
Post by: Cathy on May 08, 2013, 03:52:36 PM
The first time I ran this, it worked.  The second time it did not.  If I change the rename to -test1, it will work one more time.
Title: Re: Rename Paperspace Layout OBDX
Post by: BlackBox on May 08, 2013, 04:18:23 PM
The first time I ran this, it worked.  The second time it did not.  If I change the rename to -test1, it will work one more time.

Please clarify the phrase "it worked"... What exactly was done?
Title: Re: Rename Paperspace Layout OBDX
Post by: Cathy on May 08, 2013, 04:29:50 PM
It ran for me in 2012, renaming Layout1 tab to test in the active drawing. 

It worked as above.  No error message. 

I'm confused what the OP is trying to do.  If he's trying to change the name of the layout tab in the saved -test drawing, wouldn't he just use saveas to create the file, and then open the saved drawing with DBX, change the layout name and resave it?  Or change the name in the active drawing, and then do a saveas? 
Title: Re: Rename Paperspace Layout OBDX
Post by: ronjonp on May 08, 2013, 04:42:52 PM
I'm trying to rename a tab in an existing drawing opened via DBX.
Title: Re: Rename Paperspace Layout OBDX
Post by: BlackBox on May 08, 2013, 04:58:15 PM
It ran for me in 2012, renaming Layout1 tab to test in the active drawing. 

It worked as above.  No error message. 

I'm confused what the OP is trying to do.  If he's trying to change the name of the layout tab in the saved -test drawing, wouldn't he just use saveas to create the file, and then open the saved drawing with DBX, change the layout name and resave it?  Or change the name in the active drawing, and then do a saveas?

For ronjonp's purposes, I'm pretty sure he's got what he needed from posing the original question at this point.

Forgive my reason for questioning you, Cathy; I thought it was understood that the renaming of the Active Document's Layout Object was not the intended goal, but as ronjonp has already clarified, instead to rename a Layout Object via DBX... That said, the creation of the *-test.dwg was for testing purposes only... Presumably, the intent was to iterated a directory of other drawings (not saved as from the active document). Just speculation on my part.

Cheers