vla-open \ vla-close \ copy table objects

vla-open \ vla-close \ copy table objects

Moshe-A
Mentor Mentor
2,160 Views
3 Replies
Message 1 of 4

vla-open \ vla-close \ copy table objects

Moshe-A
Mentor
Mentor

ok today is my day  Smiley LOL

 

i  open another database (a dwt or a dwg):

(setq dbx (vlax-create-object (strcat "ObjectDBX.AxDbDocument." (substr (getvar 'acadver) 1 2))))
(vla-open dbx "MyTemp.dwt")

 

(vl-open) returns nil instead of document object

but i looks like the dbx object is a document object but does not have a close method

so how can i close the file?

 

i want to copy some tables object like layers, linetypes and textstyles from "MyTemp.dwt" to the current document.

the (vla-copy) is coping to the same location - not suit

the (vla-copyFrom) handles only dimension style, layout, or plot configuration - not suit

and the (vla-copyObjects) deals with Graphics objects - not suit

 

so can i copy table records?

 

Moshe

 

0 Likes
Accepted solutions (1)
2,161 Views
3 Replies
Replies (3)
Message 2 of 4

_gile
Consultant
Consultant
Accepted solution

Hi,

 

You can use CopyObjects to copy non-graphical objects, you just have to specify the right source objects with the according target owner (table or dictionary).

To 'close' the file, use the vlax-release-object function.

 

Here's a little sample

 

(vl-load-com)
(or *acad* (setq *acad* (vlax-get-acad-object)))
(or *acdoc* (setq *acdoc* (vla-get-ActiveDocument *acad*)))
(or *blocks* (setq *blocks* (vla-get-Blocks *acdoc*)))
(or *layers* (setq *layers* (vla-get-Layers *acdoc*)))

(defun gc:GetAxDbDoc (filename / majVer progId axdbdoc)
  (vl-load-com)
  (setq progId
         (if (< (setq majVer (substr (getvar 'acadver) 1 2)) "16")
           "ObjectDBX.AxDbDocument"
           (strcat "ObjectDBX.AxDbDocument." majVer)
         )
  )
  (if (setq axdbdoc (vlax-create-object progId))
    (if (vl-catch-all-apply
          'vla-open
          (list axdbdoc filename)
        )
      (not (vlax-release-object axdbdoc))
      axdbdoc
    )
  )
)

((lambda (/ doc)
   (if (setq doc (gc:GetAxDbDoc "MyTemp.dwt"))
     (progn
       (vlax-invoke doc 'CopyObjects (list (vla-Item (vla-get-Layers doc) "LayerName") ) *layers* )
       (vlax-invoke doc 'CopyObjects (list (vla-Item (vla-get-Blocks doc) "BlockName") ) *blocks* )
       (vlax-release-object doc)
     )
   )
 )
)


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 3 of 4

Moshe-A
Mentor
Mentor

Gilles,

 

thanks  alot...yes i have figured it that (vla-copyObject) is the function to do it.

but how do you explain that (vla-open) returns nil? and the documentation says it should return a  document object.

 

overall that, how do you explain the big gap between the documentation and how the function is actually works.

here is the the documentation for copyObjects, as you can see the arguments should be variants?!

when autodesk will fix this?!

 

thanks again,

Moshe

 

 

VBA:

RetVal = object.CopyObjects(Objects [, Owner] [, IDPairs])
object

Type: Database, Document

The objects this method applies to.

Objects

Access: Input-only

Type: Variant (array of Objects)

The array of primary objects to be copied. All the objects must have the same owner, and the owner must belong to the database or document that is calling this method.

Owner

Access: Input-only; optional

Type: Variant (a single object)

The new owner for the copied objects. If no owner is specified, the objects will be created with the same owner as the objects in the Objects array.

IDPairs

Access: Input-output; optional

Type: Variant (array of IDPair objects)

Information on what happened during the copy and translation process.

  • Input: an empty variant.
  • Output: an array of IDPair objects.
Return Value (RetVal)

Type: Variant (array of objects)

An array of newly created duplicate objects. Only primary objects are returned in this array. For more information on what occurred during the CopyObjects operation, or a list of objects owned by primary objects that were also copied, consult the IDPairs parameter.

 

 

 

0 Likes
Message 4 of 4

_gile
Consultant
Consultant

@Moshe-A  a écrit :
how do you explain that (vla-open) returns nil? and the documentation says it should return a  document object.

 

You should insure "MyTemp.dwt" is a valid file name.

 

(if (setq filename (findfile "MyTemp.dwt"))
  (progn
    (setq dbx (vlax-create-object (strcat "ObjectDBX.AxDbDocument." (substr (getvar 'acadver) 1 2))))
    (vla-open dbx filename)
    [...]
  )
)

 

 

@Moshe-A  a écrit :
overall that, how do you explain the big gap between the documentation and how the function is actually works.

here is the the documentation for copyObjects, as you can see the arguments should be variants?!

when autodesk will fix this?!


 

Using the 'old style' (vlax-invoke object method ...) is a work around to avoid the variant stuff.

 

(vlax-invoke doc 'CopyObjects (list (vla-Item (vla-get-Layers doc) "LayerName")) *layers*)

Works the same as:

 

(vla-CopyObjects
  doc
  (vlax-make-variant
    (vlax-safearray-fill
      (vlax-make-safearray
        vlax-vbObject
        '(0 . 0)
      )
      (list (vla-Item (vla-get-Layers doc) "LayerName"))
    )
  )
  *layers*
)

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes