TheSwamp
Code Red => VB(A) => Topic started by: Spageddie 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 ? :-)
-
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
-
8-) Thanks Kerry, i'll see what I can achieve VLAX...
In the mean time I achieved it with LISP & VBA :kewl:
-
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:
Dim Obj As VLAX, retval, TransMatrix As Variant, ContextData As Variant
ThisDrawing.Utility.GetSubEntity ent, pt, TransMatrix, ContextData, "Select object: "
Orginal Code:
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
-
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
-
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.
-
Unless I misunderstand,
ThisDrawing.Utility.GetSubEntity ObjSelected , pt, TransMatrix, ContextData, "Select object: "
Should work.
Just be carefull to type the ObjSelected correctly ..
-
The getsubentity works, but this section of the code is unable to get the information from that 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
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
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
-
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.
-
8-) Thanks for that .. I'll look into it..
-
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:
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.
-
8-) Thanks for clarifying that Glen...I was wondering how and why .... Much appreciated.. :kewl:
-
... but I really need to get to the object thru an Xref.
Handles in XREF's are arbitrary ...
A most salient point.
(http://www.theswamp.org/screens/mp/blush.gif)
This can be used to find a handle in a block ( xref ) definition, feel free to convert to equivalent vb code:
(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 --
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:
(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.
:)
-
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.
-
In case SpagEddie would benefit from a Autoplant DXF map ...
(http://www.theswamp.org/screens/mp/apmap.png)
Obviously there is buckets more but it's a start.
-
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...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.
:)
-
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.
-
8-) Hence why used a lisp/vba combo, like you said use lisp to gather the info and pass it onto the vba macro...
-
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:
-
8-) No no ... I am starting with the lisp then transfering to the VBA macro....
Works rally well to !
-
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.
-
Or you might PM SCMD (http://www.theswamp.org/forum/index.php?action=profile;u=26) and ask him.
-
Thanks 808, I did not know if he had made the transition.
-
Maybe he could post the code here? Please?