.NET

Reply
Active Contributor
FritsA4
Posts: 26
Registered: ‎09-15-2010
Message 11 of 16 (840 Views)

Re: variables set by -DWGUNITS

12-04-2011 11:53 AM in reply to: FrankLenoir

For AutoCAD MAP(2008), see the AECDWGSETUP and -DWGUNITS commands

MEASUREMENT= 1

insunits=0

insunitsdefsource=0
insunitsdeftarget=0
ANNOTATIVEDWG=0

 

Other commands related

    -dwgunits/-aecdwgunits
    -EXPORTTOAUTOCAD

 

VBA code

for each blk   ::Units =acInsertUnitsMillimeters

 

 

    Change dxf code 70 from 1 to 0 in the dictionary AEC_Vars_Dwg_Setup.

    (command "-DwgUnits" "3" "" "" "No" "No")
        (defun set_dwgunits_to_no ( / dictionary_data_list)
        (setq dictionary_data_list
        (entget
        (cdr
        (assoc
        350
        (dictsearch (namedobjdict) "AEC_VARS")
        )
        )
        )
        )
        (entmod
        (subst
        (cons 70 0)
        (assoc 70 dictionary_data_list)
        dictionary_data_list
        )
        )
        (princ)
        )


Contributor
FrankLenoir
Posts: 25
Registered: ‎09-29-2008
Message 12 of 16 (825 Views)

Re: variables set by -DWGUNITS

12-04-2011 11:58 PM in reply to: FritsA4

Can someone give a translation of this code in VB or C#?

  (defun set_dwgunits_to_no ( / dictionary_data_list)
        (setq dictionary_data_list
        (entget
        (cdr
        (assoc
        350
        (dictsearch (namedobjdict) "AEC_VARS")
        )
        )
        )
        )
        (entmod
        (subst
        (cons 70 0)
        (assoc 70 dictionary_data_list)
        dictionary_data_list
        )
        )
        (princ)
        )

 

Active Member
h-mt
Posts: 10
Registered: ‎09-22-2011
Message 13 of 16 (815 Views)

Re: variables set by -DWGUNITS

12-05-2011 12:24 AM in reply to: FritsA4

Hi,


@Frank: Thank you for your time.


@Alexander: INSUNITSDEFSOURCE and INSUNITSDEFTARGET are not affecting the Units in DWGUNITS and UNITS.


@FritsA4: AECDWGSETUP and DWGUNITS are working for a opened drawing. i am looking for an option to change the value in the drawing database. i only want to load the database because of performance issues.
as i mentioned before running a lisp routine which opens every drawing is not a solution for 500 dwgs.
If i change my Drawing Unit from mm to Meter nothing changes in the dxf section you mentioned:
(entget (cdr (assoc 350 (dictsearch (namedobjdict) "AEC_VARS"))))

So does anyone know where the Value is stored to set the Units in DWGUNITS/AECDWGSETUP/UNITS to Meters/Millimeters etc?

Thank you,
regards,
max

*Expert Elite*
Alfred.NESWADBA
Posts: 9,417
Registered: ‎06-29-2007
Message 14 of 16 (810 Views)

Re: variables set by -DWGUNITS

12-05-2011 01:10 AM in reply to: h-mt

Hi Frank,

 

You wanted to get a translation from the LISP to VB.NET, what should I say, the codesippet you showed today morning does nothing on my pc/my Civil3D. However I could imagine what it should do: list all variables within a dictionary.

 

Look to my code, it takes the NOD, looks for a "AEC_VARS" item, goes through the collection of subobjects and list all the properties (name, type, value) from them. The output to a messagebox is quite ill because theres not enough place to show all properties from all records, you could change it to whatever you want, write a file or do just a debug-breakpoint and view it.

What you can see that for me in Civil3D I find a var "LinearUnit" within the item "AEC_VARS_DWG_SETUP", so my hope is you see it in your ACA also and at least you can modify it.

   <Autodesk.AutoCAD.Runtime.CommandMethod("ADESK_listAecVars")> _
   Public Shared Sub ADESK_getCivilUnits()
      Dim tAcadDoc As Document = Application.DocumentManager.MdiActiveDocument
      Dim tAcadDocLock As DocumentLock = Nothing
      Dim tTrAct As Transaction = Nothing
      Dim tListAllVarsStr As String = ""
      Try
         tAcadDoc = Application.DocumentManager.MdiActiveDocument
         tTrAct = tAcadDoc.TransactionManager.StartTransaction

         Dim tNOD As DBDictionary = CType(tTrAct.GetObject(tAcadDoc.Database.NamedObjectsDictionaryId, OpenMode.ForRead), DBDictionary)
         If tNOD.Contains("AEC_VARS") Then
            Dim tObjID As ObjectId = CType(tNOD.Item("AEC_VARS"), ObjectId)
            If (tObjID.IsValid) AndAlso (Not tObjID.IsErased) Then
               Dim tDBObj As DBDictionary = CType(tTrAct.GetObject(tObjID, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead), DBDictionary)
               If tDBObj.Count > 0 Then
                  Dim tEnum As DbDictionaryEnumerator = tDBObj.GetEnumerator
                  Do While tEnum.MoveNext
                     tListAllVarsStr &= "DbDict: " & tEnum.Key & vbNewLine
                     Dim tSubObj As DBObject = tTrAct.GetObject(tEnum.Value, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead)
                     tListAllVarsStr &= listProperties(tSubObj)
                     tListAllVarsStr &= vbNewLine
                  Loop
               End If
               Debug.Print("")
            End If
         End If

         Call MsgBox(tListAllVarsStr)
      Catch ex As Exception
         MsgBox("Error occured" & vbNewLine & ex.Message)
      Finally
         If tTrAct IsNot Nothing Then tTrAct.Dispose() : tTrAct = Nothing
         If tAcadDocLock IsNot Nothing Then tAcadDocLock.Dispose() : tAcadDocLock = Nothing
      End Try
   End Sub


   ''' <summary>listProperties does a MINIMAL listing of the property-values of an object
   ''' 'it does not evaluate any arrays, enumerations, subobjects, ...
   ''' </summary>
   ''' <param name="Obj"></param>
   ''' <returns>a string listing prop-name, prop-type, prop-value</returns>
   ''' <remarks></remarks>
   Private Shared Function listProperties(ByVal Obj As Object) As String
      Dim tRetVal As String = ""
      If Obj IsNot Nothing Then
         Dim tPropDefs() As PropertyInfo = Obj.GetType.GetProperties()
         For Each tPropDef As PropertyInfo In tPropDefs
            Dim tValStr As String = vbTab & tPropDef.Name & vbTab & "(" & tPropDef.PropertyType.FullName & "):" & vbTab
            Try
               Dim tVal As Object = tPropDef.GetValue(Obj, Nothing)
               If tVal IsNot Nothing Then
                  tValStr &= tVal.ToString
               Else
                  tValStr &= "<nothing>"
               End If
            Catch ex As Exception
               tValStr &= "<error evaluating>"
            End Try
            tRetVal &= tValStr & vbNewLine
         Next
      End If
      Return tRetVal
   End Function

 

 

HTH, - alfred -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Contributor
FrankLenoir
Posts: 25
Registered: ‎09-29-2008
Message 15 of 16 (800 Views)

Re: variables set by -DWGUNITS

12-05-2011 01:48 AM in reply to: Alfred.NESWADBA

Hi Alfred,

Thanks very much. I think this will set me on the right track. 

Regards, Frank

Active Member
h-mt
Posts: 10
Registered: ‎09-22-2011
Message 16 of 16 (771 Views)

Re: variables set by -DWGUNITS

12-06-2011 07:40 AM in reply to: FritsA4

dear all,

 

i found the drawin unit in the following variable in the drawings aec database:

 

using AECAPP = Autodesk.Aec.ApplicationServices;

 

               public void testunit()
        {
        Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
        Editor ed = doc.Editor;
        Database db = HostApplicationServices.WorkingDatabase;
        Transaction tr = db.TransactionManager.StartTransaction();
         
        using (tr)
        {
        ObjectId objID = AECAPP.DrawingSetupVariables.GetInstance(db,false);
        AECAPP.DrawingSetupVariables dsv = (AECAPP.DrawingSetupVariables)tr.GetObject(objID, OpenMode.ForWrite);
        String from = dsv.LinearUnit.ToString();
        String to = Autodesk.Aec.BuiltInUnit.Meter.ToString();
        ed.WriteMessage("{0} to {1}.",from, to);
        dsv.LinearUnit = Autodesk.Aec.BuiltInUnit.Meter;
        tr.Commit();
        }
        }
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!