Author Topic: DXF Codes  (Read 13752 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

Spageddie

  • Guest
Re: DXF Codes
« Reply #15 on: September 20, 2005, 12:42:24 AM »
 8-) thanks for the response,

MP...that's what i'm after..the DXF codes for autoplant objects (I have managed to achieve what I wanted thru a combination of LISP and VBA)...I was more curious to know if these DXF codes could be obtained in VBA...as i already had the code for it in LISP.

But to answer your question...
From the DXF list shown..
I'm after codes 10,11 (start and end point) and 40 (pipe radius)

Glen...
As for the Vlax stuff ... It was posted as s possible solution to help achieve my goal.... found it has some benifits but by then I already had the LISP to get the info I wanted.

again thanks for all the assitance.. :kewl:

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: DXF Codes
« Reply #16 on: September 20, 2005, 07:42:47 AM »
MP...that's what i'm after..the DXF codes for autoplant objects (I have managed to achieve what I wanted thru a combination of LISP and VBA)...I was more curious to know if these DXF codes could be obtained in VBA...as i already had the code for it in LISP.

It's do-able. However ... Once upon a time I was coding in VB and trying to get dxf data and state data that was a bit of a hurdle from VB (like the overlay status of an xref IIRC). Anyway, I realized I was going about the problem bass-ackwards. I decided to do all my information gathering in LISP, then I'd hand it over to the gui portion of the application, the VB stuff (i.e. I invoked the VB stuff from LISP, not the other way round). Way easier, but mileages vary ... my point is, take a high level view of the problem at hand ... is the solution being developed in an optimum regard?

From the DXF list shown..
I'm after codes 10,11 (start and end point) and 40 (pipe radius)

I don't have Autoplant at home but I'd be really surprised if the StartPoint, EndPoint and Radius are not exposed to the Automation model, so I'm not confused why you're bothering with LISP, why not go direct from VB(A)? Certainly seems the long way home to me.

... thanks for all the assitance.. :kewl:

My pleasure. BTW, someday you'll want to read from a model's associated database. Remember this map, it will save you some time.

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

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: DXF Codes
« Reply #17 on: September 20, 2005, 10:48:37 AM »
Ok, just checked -- looks like Rebis / Bentley didn't think it was important to expose those properties ( StartPoint, EndPoint, Radius ).

Yet another reason to love Rebis / Bentley.

NOT.
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 #18 on: September 23, 2005, 10:03:26 AM »
 8-) Hence why used a lisp/vba combo, like you said use lisp to gather the info and pass it onto the vba macro...

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: DXF Codes
« Reply #19 on: September 23, 2005, 10:08:50 AM »
8-) Hence why used a lisp/vba combo, like you said use lisp to gather the info and pass it onto the vba macro...

Yep, but I believe you're going the other way 'round no?. You're starting in VBA and then asking LISP for help, whereas I start in LISP, do the information gathering I need and then let VB (via an in process activex dll) take care of the gui business (if dcl is too anemic).

:wink:
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 #20 on: September 26, 2005, 05:48:50 PM »
 8-) No no ... I am starting with the lisp then transfering to the VBA macro....
Works rally well to !

jjs

  • Guest
Re: DXF Codes
« Reply #21 on: November 02, 2005, 09:44:27 AM »
back at the vault, somecallmedave had made a routine to get dxf codes using VBA. Not sure what methods he used. You might be able to find it at the waybackmachine or ask some former vault member if they have it.

Bob Wahr

  • Guest
Re: DXF Codes
« Reply #22 on: November 02, 2005, 10:39:58 AM »
Or you might PM SCMD and ask him.

jjs

  • Guest
Re: DXF Codes
« Reply #23 on: November 03, 2005, 10:22:33 AM »
Thanks 808, I did not know if he had made the transition.

jjs

  • Guest
Re: DXF Codes
« Reply #24 on: December 06, 2005, 06:31:56 PM »
Maybe he could post the code here? Please?