TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: BazzaCAD on May 05, 2008, 08:22:12 PM

Title: Copy a Layout from one dwg to anther?
Post by: BazzaCAD 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?
Title: Re: Copy a Layout from one dwg to anther?
Post by: T.Willey on May 05, 2008, 11:12:21 PM
Maybe this will help you out.

[ http://www.theswamp.org/index.php?topic=19721.msg240368#msg240368 ]
Title: Re: Copy a Layout from one dwg to anther?
Post by: VovKa on May 06, 2008, 03:48:30 AM
why dbx?
Code: [Select]
(vl-cmdf "._-LAYOUT" "_TEMPLATE" DwgName LayoutName)
Title: Re: Copy a Layout from one dwg to anther?
Post by: deegeecees on May 06, 2008, 11:07:57 AM
why dbx?
Code: [Select]
(vl-cmdf "._-LAYOUT" "_TEMPLATE" DwgName LayoutName)

Thats just...  wow. Thanks Vovka!
Title: Re: Copy a Layout from one dwg to anther?
Post by: T.Willey 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.
Title: Re: Copy a Layout from one dwg to anther?
Post by: deegeecees 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?
Title: Re: Copy a Layout from one dwg to anther?
Post by: T.Willey 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.
Title: Re: Copy a Layout from one dwg to anther?
Post by: deegeecees on May 06, 2008, 11:23:05 AM
I hear ya. I'm putting on my 2nd pot of coffee too.

 :-)
Title: Re: Copy a Layout from one dwg to anther?
Post by: BazzaCAD 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
Title: Re: Copy a Layout from one dwg to anther?
Post by: VovKa 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)|;
Title: Re: Copy a Layout from one dwg to anther?
Post by: gile 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)
      )
    )
  )
)
Title: Re: Copy a Layout from one dwg to anther?
Post by: VovKa on May 08, 2008, 10:56:02 AM
i updated my code above, using your advice, thanks gile