Author Topic: Copy a Layout from one dwg to anther?  (Read 5238 times)

0 Members and 1 Guest are viewing this topic.

BazzaCAD

  • Bull Frog
  • Posts: 269
  • Cylons will kill you
Copy a Layout from one dwg to anther?
« on: May 05, 2008, 08:22:12 PM »
Does anyone have some ObjectDBX code to copy an entire layout from one DWG to anther?
Similar to the way the Design Center allows you to drag a layout for one dwg to anther...
I've coped blocks from DWG to DWG. Is it much harder to copy the layout, isn't it just anther block?
a.k.a. Barry Ralphs

T.Willey

  • Needs a day job
  • Posts: 5218
Re: Copy a Layout from one dwg to anther?
« Reply #1 on: May 05, 2008, 11:12:21 PM »
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

VovKa

  • Swamp Rat
  • Posts: 1163
  • Ukraine
Re: Copy a Layout from one dwg to anther?
« Reply #2 on: May 06, 2008, 03:48:30 AM »
why dbx?
Code: [Select]
(vl-cmdf "._-LAYOUT" "_TEMPLATE" DwgName LayoutName)

deegeecees

  • Guest
Re: Copy a Layout from one dwg to anther?
« Reply #3 on: May 06, 2008, 11:07:57 AM »
why dbx?
Code: [Select]
(vl-cmdf "._-LAYOUT" "_TEMPLATE" DwgName LayoutName)

Thats just...  wow. Thanks Vovka!

T.Willey

  • Needs a day job
  • Posts: 5218
Re: Copy a Layout from one dwg to anther?
« Reply #4 on: May 06, 2008, 11:10:34 AM »
why dbx?
Code: [Select]
(vl-cmdf "._-LAYOUT" "_TEMPLATE" DwgName LayoutName)
One reason is you can copy from and unopend drawing to another unopened drawing.  I have a copy block routine that will do it this way.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

deegeecees

  • Guest
Re: Copy a Layout from one dwg to anther?
« Reply #5 on: May 06, 2008, 11:14:53 AM »
why dbx?
Code: [Select]
(vl-cmdf "._-LAYOUT" "_TEMPLATE" DwgName LayoutName)
One reason is you can copy from and unopend drawing to another unopened drawing.  I have a copy block routine that will do it this way.

If you want Design Center similarity, wouldn't you need to be in the drawing anyway?

T.Willey

  • Needs a day job
  • Posts: 5218
Re: Copy a Layout from one dwg to anther?
« Reply #6 on: May 06, 2008, 11:16:14 AM »
why dbx?
Code: [Select]
(vl-cmdf "._-LAYOUT" "_TEMPLATE" DwgName LayoutName)
One reason is you can copy from and unopend drawing to another unopened drawing.  I have a copy block routine that will do it this way.

If you want Design Center similarity, wouldn't you need to be in the drawing anyway?

Yea, but... but... It's early, and I only responded to the 'why dbx?' question.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

deegeecees

  • Guest
Re: Copy a Layout from one dwg to anther?
« Reply #7 on: May 06, 2008, 11:23:05 AM »
I hear ya. I'm putting on my 2nd pot of coffee too.

 :-)

BazzaCAD

  • Bull Frog
  • Posts: 269
  • Cylons will kill you
Re: Copy a Layout from one dwg to anther?
« Reply #8 on: May 06, 2008, 01:15:38 PM »
why dbx?
Code: [Select]
(vl-cmdf "._-LAYOUT" "_TEMPLATE" DwgName LayoutName)

Wow you learn something new everyday...
Thx VovKa
a.k.a. Barry Ralphs

VovKa

  • Swamp Rat
  • Posts: 1163
  • Ukraine
Re: Copy a Layout from one dwg to anther?
« Reply #9 on: May 06, 2008, 04:49:22 PM »
that's what T.Willey is talking about:
Code: [Select]
(vl-load-com)
(defun ImportSmth
     (Smth
      DwgName
      NamesList
      /
      dbxDocObj
      dbxSmthObj
      dbxObjList
      AcadObj
      AcDocObj
      SmthCollectObj
      *error*
     )
  (car
    (list
      (and
(= (type Smth) (type DwgName) 'STR)
(listp NamesList)
(setq Smth (strcase Smth))
(vl-position
  Smth
  (list "LAYERS"
"BLOCKS"
"TEXTSTYLES"
"LAYOUTS"
"PLOTCONFIGURATIONS"
"DIMSTYLES"
"LINETYPES"
"USERCOORDINATESYSTEMS"
  )
)
(setq DwgName (findfile DwgName))
(setq AcadObj (vlax-get-acad-object))
(setq AcDocObj (vla-get-ActiveDocument AcadObj))
(not (vl-catch-all-error-p
       (setq SmthCollectObj
      (vl-catch-all-apply 'vlax-get-property (list AcDocObj Smth))
       )
     )
)
(setq NamesList
       (vl-remove-if-not
(function (lambda (n)
     (vl-catch-all-error-p
       (vl-catch-all-apply 'vla-item (list SmthCollectObj n))
     )
   )
)
NamesList
       )
)
(not (vl-catch-all-error-p
       (setq dbxDocObj (vl-catch-all-apply
'vla-GetInterfaceObject
(list AcadObj
       (strcat "ObjectDBX.AxDbDocument."
       (substr (getvar "ACADVER") 1 2)
       )
)
       )
       )
     )
)
(not (vl-catch-all-error-p
       (vl-catch-all-apply 'vla-open (list dbxDocObj DwgName))
     )
)
(not (vl-catch-all-error-p
       (setq dbxSmthObj
      (vl-catch-all-apply 'vlax-get-property (list dbxDocObj Smth))
       )
     )
)
(setq NamesList
       (vl-remove-if
'vl-catch-all-error-p
(mapcar
   (function
     (lambda (b) (vl-catch-all-apply 'vla-item (list dbxSmthObj b)))
   )
   NamesList
)
       )
)
(if (vl-position Smth (list "LAYOUTS" "PLOTCONFIGURATIONS"))
  (apply
    'and
    (mapcar
      (function
(lambda (Name)
  ((lambda (PS dbxPS)
     (if
       (not (or (vl-catch-all-error-p PS)
(vl-catch-all-error-p dbxPS)
(and (vl-catch-all-error-p
       (vl-catch-all-apply 'vla-CopyFrom (list PS dbxPS))
     )
     (not (vla-Delete PS))
)
    )
       )
(if (= Smth "LAYOUTS")
  (progn (setq dbxObjList nil)
(vlax-for Obj (vla-get-Block dbxPS)
   (setq dbxObjList (cons Obj dbxObjList))
)
(if (vl-catch-all-error-p
       (vl-catch-all-apply
'vlax-invoke
(list dbxDocObj
       'CopyObjects
       (reverse dbxObjList)
       (vla-get-Block PS)
)
       )
     )
   (vla-Delete PS)
   t
)
  )
  t
)
     )
   )
    (vl-catch-all-apply
      'vla-Add
      (list SmthCollectObj (vla-get-Name Name))
    )
    Name
  )
)
      )
      NamesList
    )
  )
  (not (vl-catch-all-error-p
(vl-catch-all-apply
   'vlax-invoke
   (list dbxDocObj 'CopyObjects NamesList SmthCollectObj)
)
       )
  )
)
(not (vla-Regen AcDocObj acActiveViewport))
      )
      (mapcar (function
(lambda (Obj)
  (and Obj (not (vl-catch-all-error-p Obj)) (vlax-release-object Obj))
)
      )
      (list dbxSmthObj dbxDocObj SmthCollectObj AcDocObj AcadObj)
      )
    )
  )
)
;|(ImportSmth "Layers" DwgName NamesList)
(ImportSmth "Blocks" DwgName NamesList)
(ImportSmth "TextStyles" DwgName NamesList)
(ImportSmth "Layouts" DwgName NamesList)
(ImportSmth "PlotConfigurations" DwgName NamesList)
(ImportSmth "DimStyles" DwgName NamesList)
(ImportSmth "LineTypes" DwgName NamesList)
(ImportSmth "UserCoordinateSystems" DwgName NamesList)|;
« Last Edit: May 08, 2008, 10:56:49 AM by VovKa »

gile

  • Water Moccasin
  • Posts: 2233
  • Marseille, France
Re: Copy a Layout from one dwg to anther?
« Reply #10 on: May 07, 2008, 02:56:59 AM »
Hi,

Here's an example using dbx (no error handler).
A layout is mainly composed by two objects : the layout object (plot settings and visual properties) which can be copied by vla-CopyFrom, and an block (graphic objects and viewports) which components can be copied by vla-CopyObjects.

In this example odbx is the document opened with DBX (source), *acdoc* the active document (target).

Code: [Select]
(vlax-for l (vla-get-Layouts odbx)
  (if (/= (setq name (vla-get-Name l)) "Model")
    (progn
      (setq objlst nil)
      (vlax-for o (vla-get-Block l)
(setq objlst (cons o objlst))
      )
      (setq newlay
     (vla-add (vla-get-Layouts *acdoc*)
      (strcat
name
"_copy"
      )
     )
      )
      (vla-Copyfrom newlay l)
      (vlax-invoke
odbx
'CopyObjects
(reverse objlst)
(vla-get-Block newlay)
      )
    )
  )
)
Speaking English as a French Frog

VovKa

  • Swamp Rat
  • Posts: 1163
  • Ukraine
Re: Copy a Layout from one dwg to anther?
« Reply #11 on: May 08, 2008, 10:56:02 AM »
i updated my code above, using your advice, thanks gile