Author Topic: ObjectDBX  (Read 4071 times)

0 Members and 1 Guest are viewing this topic.

Humbertogo

  • Guest
ObjectDBX
« on: September 28, 2006, 06:50:23 AM »
is there a way to read some systemvariables with ObjectDBX?

Jeff_M

  • King Gator
  • Posts: 3946
  • C3D user & customizer
Re: ObjectDBX
« Reply #1 on: September 28, 2006, 01:07:06 PM »
no....not that I'm aware of :(

FengK

  • Guest
Re: ObjectDBX
« Reply #2 on: September 28, 2006, 01:20:49 PM »
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.

deegeecees

  • Guest
Re: ObjectDBX
« Reply #3 on: September 28, 2006, 02:31:50 PM »
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.

Humbertogo

  • Guest
Re: ObjectDBX
« Reply #4 on: September 28, 2006, 05:22:47 PM »
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
« Last Edit: September 28, 2006, 05:24:08 PM by Humbertogo »

Fatty

  • Guest
Re: ObjectDBX
« Reply #5 on: September 29, 2006, 05:59:24 AM »
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:

Code: [Select]
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'~

Chuck Gabriel

  • Guest
Re: ObjectDBX
« Reply #6 on: September 29, 2006, 07:56:51 AM »
What version of AutoCAD are you using?

Humbertogo

  • Guest
Re: ObjectDBX
« Reply #7 on: September 29, 2006, 09:04:32 AM »
I use Autocad mechanical 2006

Chuck Gabriel

  • Guest
Re: ObjectDBX
« Reply #8 on: September 29, 2006, 10:53:04 AM »
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?

Humbertogo

  • Guest
Re: ObjectDBX
« Reply #9 on: September 29, 2006, 11:06:24 AM »
Quote
Are you interested in giving it a try?

oh yes I'm

Chuck Gabriel

  • Guest
Re: ObjectDBX
« Reply #10 on: September 29, 2006, 11:13:08 AM »
Give me a little time to formulate something, and I'll post back with some starter code.

Chuck Gabriel

  • Guest
Re: ObjectDBX
« Reply #11 on: September 29, 2006, 12:01:29 PM »
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.

Code: [Select]
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;
            }
        }
    }
}

Humbertogo

  • Guest
Re: ObjectDBX
« Reply #12 on: September 29, 2006, 12:22:50 PM »
thanks Chuck Gabriel

Chuck Gabriel

  • Guest
Re: ObjectDBX
« Reply #13 on: September 29, 2006, 12:33:43 PM »
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.

Humbertogo

  • Guest
Re: ObjectDBX
« Reply #14 on: September 29, 2006, 01:54:44 PM »
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

Chuck Gabriel

  • Guest
Re: ObjectDBX
« Reply #15 on: September 29, 2006, 02:35:26 PM »
Sorry you couldn't use what I posted.  Maybe somebody else will find it useful.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: ObjectDBX
« Reply #16 on: September 29, 2006, 03:34:06 PM »
I'm sure they will Chuck .. :lol:
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

Humbertogo

  • Guest
Re: ObjectDBX
« Reply #17 on: October 04, 2006, 02:10:40 AM »
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
                                               
« Last Edit: October 04, 2006, 04:24:59 AM by Humbertogo »

MikeJarosz

  • Guest
Re: ObjectDBX
« Reply #18 on: October 27, 2006, 06:46:15 PM »
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.