Field and linked object

Field and linked object

TONELLAL
Collaborator Collaborator
2,121 Views
5 Replies
Message 1 of 6

Field and linked object

TONELLAL
Collaborator
Collaborator

Hello,

I have some drawings with a lot of fields in tables. I'm looking for a way to retrieve the object from the field, is it possible ?

 

For example :

I have lines in my drawing. For each one I've created a field to extract the length in a table. Now, I would know which line has its length written in the 3rd row of my table.

 

0 Likes
Accepted solutions (1)
2,122 Views
5 Replies
Replies (5)
Message 2 of 6

Ed__Jobe
Mentor
Mentor
Accepted solution

Here are the steps you need to do.

First, select the text in the cell that contains the field. It will contain text that is formatted like this "%<\AcObjProp Object(%<\_ObjId 8796088073328>%).Length \f "%lu6">%".

Use string functions to extract the ObjectID number from the text string.

Loop through the AcadEntity objects in modelspace (or ps) examining the ObjectID property to find the right entity.

Once you have id'd it, add it to a selectionset or highlight it.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 3 of 6

TONELLAL
Collaborator
Collaborator

Thanks for your help !

Hereunder the code, most important lines are in bold.

Last question : once I the object is selected, how can I display its properties in the AutoCAD Properties dialog box ? Exactly like when I click on an object, its properties and grips are displayed. If I Highlight and Select the object (VBA), it is highlighted. It is also selected in VBA-side, but not in user-side.

Sub Find_object_by_field()
'Zoom on the object concerned by the selected field
Dim oSel As AcadSelectionSet Dim oTxt As AcadMText Dim oObjectId As Variant Dim oObj As AcadObject Dim ObjType As String Dim txtField As String Dim varPointMin As Variant Dim varPointMax As Variant Dim point1(0 To 2) As Double Dim point2(0 To 2) As Double Const cstMargeZoom = 0.6 On Error Resume Next ThisDrawing.SelectionSets("oSel").Delete On Error GoTo 0 ThisDrawing.SelectionSets.Add ("oSel") Set oSel = ThisDrawing.SelectionSets("oSel") 'Select the object oSel.SelectOnScreen Set oObj = oSel(0) ObjType = TypeName(oObj) 'Test if the selected object is a Text or MText
if ObjType = "IAcadText" Or ObjType = "IAcadMText" Then txtField = oObj.FieldCode MsgBox (txtField) Else MsgBox ("Select a text") Exit Sub End If 'From the text, extract the Object Id
varObjId = Val(Split(Split(txtField, "_ObjId")(1), ">")(0)) 'Find the object
For Each objacad In ThisDrawing.ModelSpace If objacad.ObjectID = varObjId Then ReDim ssobjs(0) As AcadEntity Set ssobjs(0) = objacad oSel.AddItems ssobjs oSel.Highlight (True) 'Zoom on the object
objacad.GetBoundingBox varPointMin, varPointMax point1(0) = varPointMin(0) point1(1) = varPointMin(1) point1(2) = 0 point2(0) = varPointMax(0) point2(1) = varPointMax(1) point2(2) = 0 ZoomWindow point1, point2 ZoomScaled cstMargeZoom, acZoomScaledRelative Exit For End If Next objacad End Sub

 

0 Likes
Message 4 of 6

Ed__Jobe
Mentor
Mentor

VBA can't do what you want. It will only highlight. You have to set the PickFirstSelectionSet using lisp. You can run the lisp from your vba though. Make sure this is the last line. "ent" is the AcadEntity that you want to select.

 

ThisDrawing.SendCommand "(sssetfirst nil (setq ss (ssadd (handent """ & ent.Handle & """))))" & vbCrLf

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 5 of 6

TONELLAL
Collaborator
Collaborator
Ok !
I already have a selectionset containing the object, so I don't think I need to use Pickfirstselectionset ?
I don't see difference between :

ThisDrawing.SendCommand "(sssetfirst nil (setq ss (ssadd (oObj """ & ent.Handle & """))))" & vbCrLf, where oObj is the AcadEntity to select
And
oSel.Highlight (True), where oSel is the selectionset containing only oObj

Alain
******************************************************************************************
CONFIDENTIALITY NOTICE
This e-mail and any attachment are confidential and may be privileged or otherwise protected from disclosure. It is solely intended for the person(s) named above. If you are not the intended recipient, any reading, use, disclosure, copying or distribution of all or parts of this e-mail or associated attachments is strictly prohibited. If you are not an intended recipient, please notify the sender immediately by replying to this message or by telephone and delete this e-mail and any attachments permanently from your system.
0 Likes
Message 6 of 6

Ed__Jobe
Mentor
Mentor

The PickFirstSelectionSet is a spectial set containing the objects that are highlighted and gripped, So you have to set it to contain the objects you want. The two lines you showed look like they should both do the same thing, but as I mentioned before, vba won't do it. It has never worked. In vba, the PickFirstSelectionSet property is read-only. So, you have to use lisp.

 

Yes, you can remove the code dealing with the selection set you created. Especially if you're only ever going to deal with one entity.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature