Author Topic: DXF Codes  (Read 13579 times)

0 Members and 1 Guest are viewing this topic.

Spageddie

  • Guest
DXF Codes
« on: September 15, 2005, 08:49:45 PM »
I'm want to get the DXF codes from an object in a drawing..
I know this can done using LISP (entget (car (entsel))) , but can this done in VBA ?

If this is possible, can you post some sample code ?   :-)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: DXF Codes
« Reply #1 on: September 15, 2005, 09:14:49 PM »
Hi Eddie,

I found this one.  Their VLAX interface  is required.
Haven't tried it personally, so posting here as a nudge for anyone who has ..

http://www.acadx.com/
GetAssociationList in the Visual Basic section.

I think it may be what you need ..

Kerry
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Spageddie

  • Guest
Re: DXF Codes
« Reply #2 on: September 17, 2005, 08:45:28 AM »
 8-) Thanks Kerry, i'll see what I can achieve VLAX...
In the mean time I achieved it with LISP & VBA :kewl:

Spageddie

  • Guest
Re: DXF Codes
« Reply #3 on: September 18, 2005, 07:19:02 PM »
Kerry,
I had a look at the link you posted and it looks like it will help me out.... 8-)

I'm just curious...with the visuallisp part of it...how can this be modified to work with xrefs ?
using getsubentity ?

Modification:
Code: [Select]
    Dim Obj As VLAX, retval, TransMatrix As Variant, ContextData As Variant

    ThisDrawing.Utility.GetSubEntity ent, pt, TransMatrix, ContextData, "Select object: "

Orginal Code:
Code: [Select]
Public Function GetAssociationList(ent As AcadEntity)

    Dim obj As VLAX, ent As AcadEntity, retVal
   
    ThisDrawing.Utility.GetEntity ent, pt, "Select object: "
   
    Set obj = New VLAX
    obj.EvalLispExpression "(defun getEDD (handle / lst) (vlax-safearray-fill (vlax-make-safearray " & _
                           "vlax-vbvariant (cons 0 (1- (length (setq lst (entget (handent handle))))))" & _
                           ") (mapcar '(lambda (x) (vlax-make-variant (vlax-safearray-fill" & _
                           "(vlax-make-safearray vlax-vbvariant '(0 . 1))(list (vlax-make-variant (car x))" & _
                           "(vlax-make-variant(cond ((= (type (cdr x)) 'ENAME) (vla-get-objectid" & _
                           "(vlax-ename->vla-object (cdr x)))) ((= (type (cdr x)) 'LIST) (vlax-safearray-fill" & _
                           "(vlax-make-safearray vlax-vbVariant (cons 0 (1- (length (cdr x))))) (cdr x)" & _
                           ")) (t (cdr x)))))))) lst)))"
    obj.SetLispSymbol "handle", ent.Handle
    retVal = obj.EvalLispExpression("(getedd handle)")
    obj.NullifySymbol "geteed", "handle"
    GetAssociationList = retVal

End Function

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: DXF Codes
« Reply #4 on: September 18, 2005, 07:43:48 PM »
Hi Eddie, Which properties are you actually trying to determine.

Seems to me that using VBA direct MAY be more economical. .. providing the info is availablre from VBA

I dont do much complex work with VBA. If you are able to be a little more explicit, one of the guts here may be able to help. I do know that Glenn has made a particular study of Xrefs
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Spageddie

  • Guest
Re: DXF Codes
« Reply #5 on: September 18, 2005, 08:00:06 PM »
Kerry,
The objects are out of AutoPLANT Piping...the object itself is refered to as AT_CYLINDER
I have successfully used the code on one of these objects, but I really need to get to the object thru an Xref.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: DXF Codes
« Reply #6 on: September 18, 2005, 08:14:43 PM »
Unless I misunderstand,

ThisDrawing.Utility.GetSubEntity ObjSelected , pt, TransMatrix, ContextData, "Select object: "

Should work.

Just be carefull to type the ObjSelected correctly ..
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Spageddie

  • Guest
Re: DXF Codes
« Reply #7 on: September 18, 2005, 08:35:34 PM »
The getsubentity works, but this section of the code is unable to get the information from that object.

Code: [Select]
Set Obj = New VLAX
    Obj.EvalLispExpression "(defun getEDD (handle / lst) (vlax-safearray-fill (vlax-make-safearray " & _
                           "vlax-vbvariant (cons 0 (1- (length (setq lst (entget (handent handle))))))" & _
                           ") (mapcar '(lambda (x) (vlax-make-variant (vlax-safearray-fill" & _
                           "(vlax-make-safearray vlax-vbvariant '(0 . 1))(list (vlax-make-variant (car x))" & _
                           "(vlax-make-variant(cond ((= (type (cdr x)) 'ENAME) (vla-get-objectid" & _
                           "(vlax-ename->vla-object (cdr x)))) ((= (type (cdr x)) 'LIST) (vlax-safearray-fill" & _
                           "(vlax-make-safearray vlax-vbVariant (cons 0 (1- (length (cdr x))))) (cdr x)" & _
                           ")) (t (cdr x)))))))) lst)))"
    Obj.SetLispSymbol "handle", ent.Handle
    retval = Obj.EvalLispExpression("(getedd handle)")
    Obj.NullifySymbol "geteed", "handle"
    GetAssociationList = retval

retval ends up empty...

I got a feeling it may have something to do with class module that runs with this. (downloaded it from acadx)

For your information: this is from the acadx site
Quote
Public Function GetAssociationList(ent As AcadEntity)

    Dim obj As VLAX, ent As AcadEntity, retVal
   
    ThisDrawing.Utility.GetEntity ent, pt, "Select object: "
   
    Set obj = New VLAX
    obj.EvalLispExpression "(defun getEDD (handle / lst) (vlax-safearray-fill (vlax-make-safearray " & _
                           "vlax-vbvariant (cons 0 (1- (length (setq lst (entget (handent handle))))))" & _
                           ") (mapcar '(lambda (x) (vlax-make-variant (vlax-safearray-fill" & _
                           "(vlax-make-safearray vlax-vbvariant '(0 . 1))(list (vlax-make-variant (car x))" & _
                           "(vlax-make-variant(cond ((= (type (cdr x)) 'ENAME) (vla-get-objectid" & _
                           "(vlax-ename->vla-object (cdr x)))) ((= (type (cdr x)) 'LIST) (vlax-safearray-fill" & _
                           "(vlax-make-safearray vlax-vbVariant (cons 0 (1- (length (cdr x))))) (cdr x)" & _
                           ")) (t (cdr x)))))))) lst)))"
    obj.SetLispSymbol "handle", ent.Handle
    retVal = obj.EvalLispExpression("(getedd handle)")
    obj.NullifySymbol "geteed", "handle"
    GetAssociationList = retVal

End Function

Purpose
Returns the entity definition data for the specified entity

Arguments
An AcadEntity

Example
retVal = GetAssociationList(poly)

Notes
The returned list is a variant array. Each element of the array represents a dotted pair.
This routine requires the use of the VLAX class module

NOTE: vlax.cls contained in attached ZIP

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: DXF Codes
« Reply #8 on: September 18, 2005, 09:02:57 PM »
If memory serves me correctly (not a good track record) I recall years ago Frank reporting that vlax wasn't running correctly when running in different AutoCAD versions.

You need to look for a statement in vlax class constructor that is something like:

ThisDrawing.Application.GetInterfaceObject("VL.Application.1")

And change it to the proper version number, like:

ThisDrawing.Application.GetInterfaceObject("VL.Application.15")

or

ThisDrawing.Application.GetInterfaceObject("VL.Application.16")

Suggestion: Rewrite the constructor so it will run in any version of AutoCAD.

/all guesses.

Edit: fix typos.
« Last Edit: September 18, 2005, 10:07:28 PM by MP »
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Spageddie

  • Guest
Re: DXF Codes
« Reply #9 on: September 19, 2005, 01:24:12 AM »
 8-) Thanks for that .. I'll look into it..

Glenn R

  • Guest
Re: DXF Codes
« Reply #10 on: September 19, 2005, 04:14:03 AM »
Handles in XREF's are arbitrary.This means that it's possible to have the same handle in both the current drg and the xref, hence that vlisp function is failing as it uses handent.

From the Help:

Quote
Entities in drawings that are cross-referenced by way of XREF Attach are not actually part of the current drawing; their handles are unchanged but cannot be accessed by handent. However, when drawings are combined by means of INSERT, INSERT *, XREF Bind (XBIND), or partial DXFIN, the handles of entities in the incoming drawing are lost, and incoming entities are assigned new handle values to ensure each handle in the current drawing remains unique.

Spageddie

  • Guest
Re: DXF Codes
« Reply #11 on: September 19, 2005, 06:29:48 AM »
 8-) Thanks for clarifying that Glen...I was wondering how and why .... Much appreciated.. :kewl:

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: DXF Codes
« Reply #12 on: September 19, 2005, 06:43:45 AM »
Quote from: Spageddie
... but I really need to get to the object thru an Xref.

Quote from: Glenn
Handles in XREF's are arbitrary ...

A most salient point.



This can be used to find a handle in a block ( xref ) definition, feel free to convert to equivalent vb code:

Code: [Select]
(defun FindHandleInBlockDef ( name handle / data ename result )
 
    (setq ename (cdr (assoc -2 (tblsearch "block" name))))
 
    (vl-catch-all-apply
       '(lambda ( )
            (while ename
                (if (eq handle (cdr (assoc 5 (entget ename))))
                    (setq
                        result ename
                        data   (exit)
                    )
                )
                (setq ename  (entnext ename))
            )
        )
    )
 
    result
 
)

But Mr. Spageddie -- What is your ultimate goal? Back in your original post you said --

Quote from: Spageddie
I'm want to get the DXF codes from an object in a drawing. I know this can done using LISP (entget (car (entsel))) , but can this done in VBA?

Not quite right if the object is buried in an xref, you need to call nentsel:

Code: [Select]
(entget (car (nentsel)))
But still, what's the ultimate goal? The Autoplant scheme involves the use of components (they don't host a lot of data themselves) which are linked via master objects (AT_Master) which can be found in a component's xdata (look for "AT_GRP") which subsequently hosts the link to the main database entry (via xdata entry "GN") ... but where are ya going with all this?

If I may be so bold to ask.

:)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Glenn R

  • Guest
Re: DXF Codes
« Reply #13 on: September 19, 2005, 06:58:09 AM »
If it was me and I absolutely HAD to use that vlax stuff (read: never), then use objectId's instead of handles.

For instance, in vlisp I seem to remember there is a function to convert an objectid to a vla-object and then convert that vla-object to an ename...then you can entget the little blighter...which will give you the entity's definition list.

I also would like to know WHY you need the dxf list and where you're heading.

Cheers,
GleNN.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: DXF Codes
« Reply #14 on: September 19, 2005, 07:51:46 PM »
In case SpagEddie would benefit from a Autoplant DXF map ...



Obviously there is buckets more but it's a start.
« Last Edit: September 19, 2005, 09:34:10 PM by MP »
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst