TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started 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?
-
Maybe this will help you out.
[ http://www.theswamp.org/index.php?topic=19721.msg240368#msg240368 ]
-
why dbx?
(vl-cmdf "._-LAYOUT" "_TEMPLATE" DwgName LayoutName)
-
why dbx?
(vl-cmdf "._-LAYOUT" "_TEMPLATE" DwgName LayoutName)
Thats just... wow. Thanks Vovka!
-
why dbx?
(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.
-
why dbx?
(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?
-
why dbx?
(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.
-
I hear ya. I'm putting on my 2nd pot of coffee too.
:-)
-
why dbx?
(vl-cmdf "._-LAYOUT" "_TEMPLATE" DwgName LayoutName)
Wow you learn something new everyday...
Thx VovKa
-
that's what T.Willey is talking about:
(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)|;
-
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).
(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)
)
)
)
)
-
i updated my code above, using your advice, thanks gile