Finding if a drawing is Metric or Imperial by accessing its database

Finding if a drawing is Metric or Imperial by accessing its database

GeeHaa
Collaborator Collaborator
1,516 Views
10 Replies
Message 1 of 11

Finding if a drawing is Metric or Imperial by accessing its database

GeeHaa
Collaborator
Collaborator

Hi,

Can someone tell me a way to check if a drawing is Metric or Imperial by accessing its database? I know about INSUNITS but I think that only works if the editor is open.

 

Thanks in advance.

0 Likes
Accepted solutions (3)
1,517 Views
10 Replies
Replies (10)
Message 2 of 11

hak_vz
Advisor
Advisor

 

 

(getvar 'insunits)
0 Unspecified (No units)
1 Inches
2 Feet
3 Miles
4 Millimeters
5 Centimeters
6 Meters
7 Kilometers
8 Microinches
....

 

 

Or check: INSUNITS 

 

Just type in console and it works OK

 

 

Miljenko Hatlak

EESignature

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.
Message 3 of 11

GeeHaa
Collaborator
Collaborator

Hi,

 

Thanks for the reply.

but Doesn't (getvar "INSUNITS") only work on the drawing I currently have open and not the Database of the other drawing I am accessing?  Where Mydoc represents the other drawing database. see below.

(setq mydoc (vla-getinterfaceobject
		(vlax-get-acad-object)
		(strcat "objectdbx.axDbDocument." 
                 (substr (getvar "acadver") 1 2))))
(vla-open mydoc filename)

 

0 Likes
Message 4 of 11

hak_vz
Advisor
Advisor

Try this on all open drawings

 

 

(defun c:getunits nil
	(vlax-for doc (vla-get-documents (vlax-get-acad-object))
		(princ (strcat "\n" 
			(vla-get-name doc) " ... " 
				(cdr 
					(assoc (vlax-variant-value (vlax-invoke-method doc 'getvariable "insunits"))
						'(
							(0 . "Unspecified (No units)")
							(1 . "Inches")
							(2 . "Miles")
							(4 . "Millimeters")
							(5 . "Centimeters")
							(6 . "Meters")
							(7 . "Kilometers")
							(8 . "Microinches")
							(9 . "Mils")
							(10 . "Yards")
							(11 . "Angstroms")
							(12 . "Nanometers")
							(13 . "Microns")
							(14 . "Decimeters")
							(15 . "Dekameters")
							(16 . "Hectometers")
							(17 . "Gigameters")
							(18 . "Astronomical Units")
							(19 . "Light Years")
							(20 . "Parsecs")
							(21 . "US Survey Feet") 
						)
					)
				)
			)
		)
	)
	(princ)
)
Command: GETUNITS
Drawing1.dwg ... Millimeters
Drawing2.dwg ... Unspecified (No units)
Drawing3.dwg ... Unspecified (No units)

 

 

On the same principle one can write functions that will use some of document object methods (var doc and not documents collection object i.e. (vla-get-documents (vlax-get-acad-object))

 

 

;   Activate ()
;   AuditInfo (1)
;   Close (2)
;   CopyObjects (3)
;   EndUndoMark ()
;   Export (3)
;   GetVariable (1)
;   HandleToObject (1)
;   Import (3)
;   LoadShapeFile (1)
;   New (1)
;   ObjectIdToObject (1)
;   Open (2)
;   PostCommand (1)
;   PurgeAll ()
;   Regen (1)
;   Save ()
;   SaveAs (3)
;   SendCommand (1)
;   SetVariable (2)
;   StartUndoMark ()
;   Wblock (2)

 

You can also use ODBX if you like.

Miljenko Hatlak

EESignature

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.
0 Likes
Message 5 of 11

pendean
Community Legend
Community Legend
Accepted solution
0 Likes
Message 6 of 11

GeeHaa
Collaborator
Collaborator

Thanks for the reply again. Pardon my ignorance But I think what you gave me only works for open documents. The documents I'm working on are essentially closed. I'm just opening the databases no editor involved as far as I know. No selectionsets and I'm told no system variables are accessible. I tried it though with the following result. I'm not an expert. Maybe I did something wrong.

(vlax-invoke-method mydoc 'getvariable "insunits")
; error: ActiveX Server returned the error: unknown name: GETVARIABLE

(setq units (vlax-variant-value (vlax-invoke-method mydoc 'getvariable "insunits")))
  (if (= units 4)
   (setq cvu 25.4)
   (setq cvu 1.0)
 )

Thanks.

0 Likes
Message 7 of 11

hak_vz
Advisor
Advisor
Accepted solution

@GeeHaa wrote:

; error: ActiveX Server returned the error: unknown name: GETVARIABLE

(setq units (vlax-variant-value (vlax-invoke-method mydoc 'getvariable "insunits")))
  (if (= units 4)
   (setq cvu 25.4)
   (setq cvu 1.0)
 )

Unfortunately, for ObjectDBX, there are following rules i.e. what doesn't work

No Selection Sets (use of ssget, ssname, ssdel etc)
No Command calls (command "_.line" ... etc)
No ent* methods (entmod, entupd etc)
No access to System Variables (getvar, setvar, vla-getvariable, vla-setvariable etc)

Check here

 

So in other words, use open drawing method instead: open drawing(s), extract and or set system variable and close

or use batch processing using accoreconsle which supports getvar setvar commands. Check my older posts I have somewhere posted whole guide for using lisps inside accoreconsle.

Miljenko Hatlak

EESignature

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.
0 Likes
Message 8 of 11

GeeHaa
Collaborator
Collaborator

Thanks for that. Using objectdbx is lightning fast and Some of our projects go 2000-3000 drawings as it is. How is the speed in these other methods? Right now I can do 100 drawings in about 14 seconds. Is there any other method for determining units that you can think of maybe a dictionary entry?  I found one post that referred to one but we don't have AEC. most of the drawings have the same blocks so I could get the units from that but it's kind of wonky. I'd go with viewports or title blocks but sometimes they use the clients title blocks and viewports come in all sizes.

 

Thanks.

0 Likes
Message 9 of 11

Sea-Haven
Mentor
Mentor
Accepted solution

accoreconsle may be way faster as it looks at dwg database its like OBDX possibly better as it can be ran without even open Acad. It runs within the windows operating system. You can set up a batch file to process a complete directory in one pass.

 

https://forums.autodesk.com/t5/forums/replypage/board-id/130/message-id/444989

 

https://autocadtips1.com/2013/01/30/up-and-running-with-the-2013-core-console/

Message 10 of 11

GeeHaa
Collaborator
Collaborator

I did find one property that I think I can use. I could check each block reference for insunitsfactor. If I find one that has a factor of 25.4 I assume the drawing is metric and stop looking. I need to eliminate duplicates between drawing series is there a way to remember the data between drawings when using accoreconsole other than writing to a text file?

 

Thanks

0 Likes
Message 11 of 11

Sea-Haven
Mentor
Mentor

I would expect add to a text file would be easiest method, use (open "filename" "A") the "A" is Append to file so you would have 1 file with all the information.

0 Likes