TheSwamp
Code Red => VB(A) => Topic started by: Humbertogo on September 28, 2006, 06:50:23 AM
-
is there a way to read some systemvariables with ObjectDBX?
-
no....not that I'm aware of :(
-
I vaguely remember it returns the system variables from current drawing in which your code is excuted (could be wrong).
Suggestion: Store the system variables that you're interested in in a custom dictionary or attach as xdata to some objects in the drawing and later you can access them via objectdbx.
-
Since ObjectDBX is most useful with unopened drawings, and AutoCADs' System Variables are either stored in the drawing or at the application level, why (if I may be so bold to ask) would you want to read them?
Just wondering what you're trying to do.
-
I need to check is the drawing is metric or imperial.
AutoCAD System Variables Measurement
0 is Imperial
1 is Metric
be for open or insert the files as block
-
I need to check is the drawing is metric or imperial.
AutoCAD System Variables Measurement
0 is Imperial
1 is Metric
be for open or insert the files as block
Not sure exactly but I think this will be impossible
do doing with ObjectDBX method IMHO
Try this instead:
Option Explicit
Public Function GetVars(selfiles As Variant, sysVarName As String) As Variant
Dim fName As String
Dim acdoc As AcadDocument
Dim sysvar() As Variant
Dim m As Integer
For m = 0 To UBound(selfiles)
fName = selfiles(m)
Set acdoc = Application.Documents.Open(fName, True)
ReDim Preserve sysvar(m)
sysvar(m) = acdoc.GetVariable(sysVarName)
acdoc.Close
Next m
GetVars = sysvar
End Function
Public Sub FindFile(ByRef files As Collection, strDir, strExt)
Dim strFileName
If (Right(strDir, 1) <> "\") Then
strDir = strDir & "\"
End If
strFileName = Dir(strDir & "*.*", vbDirectory)
Do While (strFileName <> "")
If (UCase(Right(strFileName, 3)) = UCase(strExt)) Then
files.Add strDir & strFileName
End If
strFileName = Dir
Loop
End Sub
Sub Test()
Dim dmod
dmod = ThisDrawing.GetVariable("SDI")
If dmod <> 0 Then
ThisDrawing.SetVariable "SDI", 0
End If
Dim path As String
path = "D:\AUTOLISP\LISPS\PRIMITIVES\#FILE&S\PURGE" '' change your path here
Dim collFiles As New Collection
Call FindFile(collFiles, path, "DWG")
Dim i As Integer
ReDim selfiles(collFiles.Count - 1) As String
For i = 1 To collFiles.Count
selfiles(i - 1) = collFiles.Item(i)
Next
Dim sysvar() As Variant
sysvar = GetVars(selfiles, "measurement")
ThisDrawing.SetVariable "SDI", dmod
Dim dataVar(999, 1) As Variant
For i = 0 To UBound(sysvar)
dataVar(i, 0) = selfiles(i)
dataVar(i, 1) = sysvar(i)
Next
End Sub
Fatty
~'J'~
-
What version of AutoCAD are you using?
-
I use Autocad mechanical 2006
-
In that case, I think there is a way you can do it through the .NET API using C# or VB.NET.
Are you interested in giving it a try?
-
Are you interested in giving it a try?
oh yes I'm
-
Give me a little time to formulate something, and I'll post back with some starter code.
-
This C# code should get you started. I translated this from some similar C++ code of mine, but hopefully the .NET gurus will come along and point out anything stupid I may have done.
using System;
using System.IO;
using System.Text;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
namespace MetricOrImperial
{
public class Main
{
public static int metricOrImperial(string fileName)
{
if(!File.Exists(fileName)) return -1;
Database db = new Database(false, true);
try
{
db.ReadDwgFile(fileName, System.IO.FileShare.Read, false, string.Empty);
return db.Measurement == MeasurementValue.English ? 1 : 0;
}
catch (Exception e)
{
Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(e.ToString());
return -1;
}
}
}
}
-
thanks Chuck Gabriel
-
You're welcome.
By the way, I think I got the return values backwards (assuming you want to follow the convention of the MEASUREMENT system variable). It should return 0 for English and 1 for Imperial.
-
The AutoCAD System Variables Measurement is the autocad way i think
for Autocad Mechanical i wrote this function
and will try to convert this function in a C# code
Public Function Mcad_StandardIsMetric() As Boolean
Set symbb = ThisDrawing.Application.GetInterfaceObject("SymBBAuto.McadSymbolBBMgr")
Set Ge = ThisDrawing.Application.GetInterfaceObject("Ge.Application")
Set stdmgr = symbb.StandardMgr
'------------------------------------------------------------
Set currStand = stdmgr.CurrentStandard
Mcad_StandardIsMetric = currStand.IsMetric
End Function
-
Sorry you couldn't use what I posted. Maybe somebody else will find it useful.
-
I'm sure they will Chuck .. :lol:
-
his solution is using the ReadDwg() method :-D
Editor editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
Database db = new Database();
db.ReadDwgFile("c:\\test.dwg",System.IO.FileShare.ReadWrite,true,""); //make sure drawing exists
db.Measurement
-
Since ObjectDBX is most useful with unopened drawings, and AutoCADs' System Variables are either stored in the drawing or at the application level, why (if I may be so bold to ask) would you want to read them?
Just wondering what you're trying to do.
The question wasn't specific to Acad. The Windows environment variables can be very useful to a programmer. The user's name, machine ID, login time and a wealth of other info can be determined from the environment. I regularly write logfiles from my applications, and I include the user, the application, date, time etc in the log file. Some of this info can only be obtained from the environment. And the user doesn't have to know your doing it!
I'm not sure Acad variables can be changed in objDBX, since I only started usingDBX. But in Acad VBA, I regularly read and alter Acad variables. For example the units can be set or reset, the precision determined, snaps turned on and off. I'd be lost without this ability.