Get value of user parameters at drawing level

Get value of user parameters at drawing level

InfoLEC
Explorer Explorer
279 Views
2 Replies
Message 1 of 3

Get value of user parameters at drawing level

InfoLEC
Explorer
Explorer

I am trying to access the values of user parameters using VBA. I can access the values of dimensionnal constraints but can't access user parameters.

 

InfoLEC_0-1737992298478.png

 

Sub get_value_of_dimension_parameter()
    'prints out the value of a dimensional constraint parameter in a message box
    
    Dim drawing As AcadDocument
    Dim ParamName As String
    Dim MdlSpc As AcadModelSpace
    Dim obj As Variant
    Dim ConstrName As String
    Dim ConstrValue As Variant
    
    ParamName = "d1"
    
    Set drawing = ThisDrawing
    Set MdlSpc = drawing.ModelSpace
    
    'loop through each object (item) of the ModelSpace
    For Each obj In MdlSpc
        'check if object type is a dimension
        If Left(obj.ObjectName, 4) = "AcDb" And Right(obj.ObjectName, 9) = "Dimension" Then
            'get name and value of active dimension
            ConstrName = obj.DimConstrName
            ConstrValue = obj.DimConstrValue
            'check if we have found the rigth dimension
            If ConstrName = ParamName Then
                MsgBox ConstrValue, vbOKOnly, ConstrName
            End If
        End If
    Next
End Sub

 

Thanks

0 Likes
280 Views
2 Replies
Replies (2)
Message 2 of 3

Ed__Jobe
Mentor
Mentor

I wanted to answer this question, because it has been asked before, but without an resolution.

 

I couldn't find much information on it so I asked Lee Ambrosius. Below is what he had to say. Thanks @ambrosl 

 

There is some basic documentation in the ObjectARX Developer’s Guide. It explains the dictionary and how it has a pointer to the actual AcDbAssocNetwork object.  The objects are spread across several places though in the drawing itself. (The user variable is stored in a dictionary of this network.)

 

What you are trying to do isn’t possible with VBA directly as there are no classes exposed at that level.  Now you could export the drawing to DXF and parse it for the information you are looking for which could take time based on the size of the drawing file.

You can use AutoLISP to pull the data, write it to a file or dictionary and then read that with VBA to get the current values.  Modifying the data would be the reverse, basically push it back to a data file or dictionary that AutoLISP would process.  The data isn’t easy to work with though as you will see in the example below it is nested pretty deep but here is some basic code that will locate the dimension and user defined parameter variables and their values.

 

Managed .NET is the best language to use for this.

Below is a sample lisp of how to do this.

 

(setq assocNetDict (assoc 350 (entget (namedobjdict))))
(setq assocNet
       (entget
                (cdr
                   (assoc
                     330
                     (reverse
                       (entget
                                (cdr
                                   (assoc 350
                                                  (entget
                                                    (cdr assocNetDict)
                                                  )
                                   )
                                )
                       )
                     )
                   )
                )
       )
)
(setq lookUpItems nil)
(foreach item assocNet
  (if (= (car item) 100)
    (if (= (cdr item) "AcDbAssocNetwork")
      (setq lookUpItems T)
    )
  )
  (if (and (= (car item) 360)(= lookUpItems T))
    (progn
      (princ (entget (cdr item)))
    )
  )
) 

((-1 . <Entity name: 220986f46d0>) (0 . ACDBASSOCVARIABLE) (5 . 275) (102 . {ACAD_REACTORS) (330 . <Entity name: 220986f46e0>) (102 . }) (330 . <Entity name: 220986f4670>) (100 . AcDbAssocAction) (90 . 2) (90 . 0) (330 . <Entity name: 220986f4670>) (360 . <Entity name: 0>) (90 . 1) (90 . 0) (90 . 0) (90 . 0) (90 . 0) (90 . 0) (90 . 0) (100 . AcDbAssocVariable) (90 . 2) (1 . d1) (1 . 13.2902766714) (1 . AcDbCalc:1.0) (1 . ) (40 . 13.2903) (290 . 0) (290 . 0) (90 . 0)) 

((-1 . <Entity name: 220986f4710>) (0 . ACDBASSOC2DCONSTRAINTGROUP) (330 . <Entity name: 220986f4670>) (5 . 279) (100 . AcDbAssocAction) (90 . 2) (90 . 0) (330 . <Entity name: 220986f4670>) (360 . <Entity name: 0>) (90 . 2) (90 . 3) (90 . 0) (90 . 0) (90 . 0) (90 . 0) (90 . 0) (90 . 2) (70 . 0) (10 0.0 0.0 0.0) (10 1.0 0.0 0.0) (10 0.0 1.0 0.0) (360 . <Entity name: 0>) (90 . 3) (360 . <Entity name: 220986f4720>) (360 . <Entity name: 220986f46f0>) (360 . <Entity name: 220986f46e0>) (90 . 6) (90 . 0) (90 . 0) (290 . 0) (90 . 6) (1 . AcConstrainedBoundedLine) (90 . 1) (1 . AcConstrainedImplicitPoint) (90 . 2) (1 . AcPointCurveConstraint) (90 . 3) (1 . AcConstrainedImplicitPoint) (90 . 4) (1 . AcPointCurveConstraint) (90 . 5) (1 . AcDistanceConstraint) (90 . 6) (90 . 1) (90 . 2) (90 . 3) (90 . 5) (70 . 1) (330 . <Entity name: 220986f4720>) (90 . 0) (10 18.511 8.74125 0.0) (10 0.833581 0.552398 0.0) (290 . 0) (10 18.511 8.74125 0.0) (11 29.5895 16.0828 0.0) (90 . 2) (90 . 2) (90 . 3) (90 . 6) (70 . 1) (330 . <Entity name: 0>) (90 . 0) (280 . 0) (90 . -1) (90 . 1) (90 . 3) (90 . 2) (90 . 2) (90 . 1) (70 . 0) (90 . 0) (290 . 1) (290 . 1) (90 . 4) (90 . 2) (90 . 5) (90 . 6) (70 . 1) (330 . <Entity name: 0>) (90 . 0) (280 . 1) (90 . -1) (90 . 1) (90 . 5) (90 . 2) (90 . 4) (90 . 1) (70 . 0) (90 . 0) (290 . 1) (290 . 1) (90 . 6) (90 . 2) (90 . 2) (90 . 4) (70 . 0) (90 . 0) (290 . 0) (290 . 1) (340 . <Entity name: 220986f46e0>) (340 . <Entity name: 220986f46f0>) (280 . 0))
 

((-1 . <Entity name: 220986f4730>) (0 . ACDBASSOCVARIABLE) (330 . <Entity name: 220986f4670>) (5 . 27B) (100 . AcDbAssocAction) (90 . 2) (90 . 0) (330 . <Entity name: 220986f4670>) (360 . <Entity name: 0>) (90 . 3) (90 . 0) (90 . 0) (90 . 0) (90 . 0) (90 . 0) (90 . 0) (100 . AcDbAssocVariable) (90 . 2) (1 . U1) (1 . 2.5) (1 . AcDbCalc:1.0) (1 . ) (40 . 2.5) (290 . 0) (290 . 0) (90 . 0))

 

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 3

jm.surprenant5D582
Community Visitor
Community Visitor

Thanks for your help, I suspected it was not possible in VBA but I had no proof. I'll try to understand your Lisp solution in a future project.

 

P.S. InfoLec and jm.surprenant is the same person. I had to use a collegue's account because mine was broken. It has since been fixed.

0 Likes