.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

variables set by -DWGUNITS

16 REPLIES 16
Reply
Message 1 of 17
FrankLenoir
5769 Views, 16 Replies

variables set by -DWGUNITS

There is a undocumented command -DWGUNITS in AutoCAD that does settings not done by the commands UNITS or INSUNITS. The settings of this command influence the scaling of inserted blocks. As far as I understand the command -DWGUNITS has its origin in the Land Development Desktop.

Does someone know which variables I have to use to do the same settings as -DWGUNITS?

I prefer code in VB.NET but C# is also OK.

 

Regards,

Frank Lenoir

16 REPLIES 16
Message 2 of 17
h-mt
in reply to: FrankLenoir

Hi,

 

i got the same question: how to set the drawing units in .net ?

All the variables (INSUNITS LUNIT etc.) wont change the dwg unit.

 

My problem is: etransmit messes up the drawing units while exporting (german aca 2011 and 2012). so one way is to reset the unit to meter is using an autolisp script which opens every drawing in autocad. works nice but it is very slow for a huge amount of drawings. i would like to fix the dwg unit via c#.net.

 

is there any possibility to set the drawing unit in .net?

 

regards,

max

Message 3 of 17

Hi,

 

>> Does someone know which variables I have to use to do the same settings as -DWGUNITS?

You can start the _UNITS command, within the dialog place the mouse cursor over the fields to change and you get the info what sysvar is used behind the fields - or other version: when the dialog is open press <F1> and you see in the help what field stands for what sysvar.

And -DWGUNITS does handle the same variables like _UNITS - except the setting for "do rescale when inserting" (whatever vocables are used for this question). For that I don't know a sysvar, sorry!

 

>> is there any possibility to set the drawing unit in .net?

Yes, you can, most sysvars are accessible direct in the AutoCAD database properties, an example:

Dim tAcadDoc as Autodesk.AutoCAD.ApplicationServices.Document
tAcadDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
tAcadDoc.Database.Unitmode = 1

 

HTH, - alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 4 of 17
h-mt
in reply to: FrankLenoir

Hi,

 

am I missing something? I cant find a var for the drawing unit. Neither in the dxf code table nor in the autocad user documentation. i even tried the F1/mouseover in dwgunits, but i didnt find the drawing units var. i can find all the others like LUPREC and LUNITS but not one controling the drawing units (Meter etc). I binged and googled it - most answers pointed to INSUNITS (which is not the drawing unit) and to "run -dwgunits manually".

 

regards,

max

 

Message 5 of 17
Alfred.NESWADBA
in reply to: h-mt

Hi,

 

does >>>this<<< help?

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 6 of 17
h-mt
in reply to: Alfred.NESWADBA

Hi,

 

in theory yes, but my drawing is already scaled correctly. iam etransmitting a dwg, drawn in meters. after etransmitting dwgunits says the file is in millimeters. the scale didnt change, so iam setting back dwgunits to meters without rescaling.

so i could basically leave the units with millimeters and just ignore it. but if i am using the file as a reference later on in aca i get a real mess if some drawings are set to mm and others to meters - because the files shouldnt be rescaled and the dims are also showing useless information. any idea?

 

regards,

max

Message 7 of 17
Alfred.NESWADBA
in reply to: h-mt

Hi,

 

>> but my drawing is already scaled correctly. iam etransmitting a dwg, drawn in meters.

>> after etransmitting dwgunits says the file is in millimeters

Just for info for me, that I can try to reproduce:

  • what AutoCAD version/service pack do you have
  • do you have a vertical product like ACA, Map3D, Civil3D, ...

 

And you tried a workflow like this (to compare we do the same):

  • set INSUNITS to 6 (look to dialog _UNITS ==> there are "Meters" now defined)
  • you saved the drawing
  • you started command _ETRANSMIT
  • you closed the current drawing
  • you opened the DWG file from the ZIP that was created by _ETRANSMIT
  • now INSUNITS is set to 4?

I have tried it with AutoCAD 2012 SP1 German ... I get 6/Meters as the result.

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 8 of 17
h-mt
in reply to: Alfred.NESWADBA

Hi,

 

iam using AutoCad Architecture 2011 and 2012 (GER) with both the latest ServicePacks and updates.

and yes to the procedure you described:

 

set INSUNITS to 6 (look to dialog _UNITS ==> there are "Meters" now defined)

saved the drawing

started command _ETRANSMIT

closed the current drawing

opened the DWG file from the ZIP that was created by _ETRANSMIT

now INSUNITS is set to 4

 

i can set INSUNITS back to 6 by lisp or c#.net - the problem is the DWGUNITS still tells me drawing units are "millimeters". i wouldnt care much about it, but my client does.

so right now i am setting the drawing back to Meters via DWGUNITS in a lisp routine. but thats just to slow for 500 dwgs.

 

regards,

max

Message 9 of 17
Alfred.NESWADBA
in reply to: h-mt

Hi, grüß Dich,

 

>> iam using AutoCad Architecture 2011 and 2012 (GER)

Sorry, then I'm the wrong one to try to reproduce it, because I have no ACA installed, sorry!

 

>> the problem is the DWGUNITS still tells me drawing units are "millimeters"

OK, and now knowing that ACA is working there may be additional sysvars or dialogs for setting units that are ACA-special ... or does the ETRANSMIT-dialog have some options to set that? (With AutoCAD 2012 I don't have a chance to modify units).

I have tried now do that wit Civil3D (which uses the same AEC-base-classes) and I don't have the problem with standard units and Civil3D-units.

 

I would suggest to ask >>>this forum for ACA<<< may be it's a known defect in ACA?.

 

Good luck, - alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 10 of 17

What about sysvars INSUNITSDEFSOURCE and INSUNITSDEFTARGET ?

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 11 of 17
FritsA4
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)
        )


Message 12 of 17
FrankLenoir
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)
        )

 

Message 13 of 17
h-mt
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

Message 14 of 17
Alfred.NESWADBA
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 ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 15 of 17

Hi Alfred,

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

Regards, Frank

Message 16 of 17
h-mt
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();
        }
        }
Message 17 of 17

Thank you that was it exactly!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost