Author Topic: Autocad MEP - VBScript - get Normal of an Object  (Read 5297 times)

0 Members and 1 Guest are viewing this topic.

Keith Brown

  • Swamp Rat
  • Posts: 601
Autocad MEP - VBScript - get Normal of an Object
« on: March 07, 2013, 06:08:56 PM »
I am working in Autocad MEP and I am trying to get the Normal of an object by using Property Sets and vbscript.  I am not sure if it is even possible.  I found this article on the Autodesk website.

http://usa.autodesk.com/adsk/servlet/ps/dl/item?siteID=123112&id=6057466&linkID=9240657  that describes how to add a property that is not an automatic property of the object and showed this vbscript code.

Code: [Select]
RESULT="--"
On Error Resume Next
Set AcadApp = GetObject(, "AutoCAD.Application")
Set Obj = AcadApp.Activedocument.Objectidtoobject("xxxxx")
RESULT= Obj.area


I modified Obj.area to instead be obj.normal but the property set only displays --.  I know the code works because i changed obj.normal to obj.rotation and it gave the rotation of the fitting.

Does anyone have any idea on how to grab the normal of an object inside of a property set in Autocad MEP or Autocad Architecture?  I need it so I can see if a duct fitting has been rotated around its centerline.  The rotation parameter only returns rotation in the XY plane.  I need a rotation in the XZ plane or ZY plane which can be determined from the Normal of the fitting.

I did use the VBA to inspect an AecbDuctFitting's properties and Normal was one of them that was available.

Thank you for any help.
Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013

Keith Brown

  • Swamp Rat
  • Posts: 601
Re: Autocad MEP - VBScript - get Normal of an Object
« Reply #1 on: March 07, 2013, 07:20:06 PM »
I really thought that something like this should work but it just returns the default string for RESULT which means that obj.normal throws an error somewhere.

Code: [Select]
RESULT="Fitting Orientation Correct"
On Error Resume Next
Set AcadApp = GetObject(, "AutoCAD.Application")
Set Obj = AcadApp.Activedocument.Objectidtoobject("[ObjectID]")
Normal = obj.normal
If Normal(2) = -1 Then
   RESULT = "UpsideDown Fitting"
End If
« Last Edit: March 08, 2013, 06:36:06 AM by Keith Brown »
Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013

fixo

  • Guest
Re: Autocad MEP - VBScript - get Normal of an Object
« Reply #2 on: March 09, 2013, 03:29:25 AM »

Keith Brown

  • Swamp Rat
  • Posts: 601
Re: Autocad MEP - VBScript - get Normal of an Object
« Reply #3 on: March 09, 2013, 10:58:32 AM »
Thank you very much Fixo!  I was able to get what I wanted from the examples provided in the posts.  Below is the working code that allows me to get the normal of an object in a property set.

Code - Visual Basic: [Select]
  1.  On Error Resume Next
  2. Set acadApp = GetObject(,"AutoCAD.Application")
  3.  
  4. 'ACADVER values:
  5. 'ACA 2010 = "18.0s (LMS Tech)"
  6. 'ACA 2011 = "18.1s (LMS Tech)"
  7. 'ACA 2012 = "18.2s (LMS Tech)"
  8. 'ACA 2013 = "19.0s (LMS Tech)"
  9. 'ACA 2014 = "19.1s (LMS Tech)"
  10.  
  11.  
  12. acadVerString = acadApp.ActiveDocument.GetVariable("ACADVER")
  13.  
  14. 'Set ACA application string, based on version running:
  15. Select Case acadVerString
  16.  
  17.        Case "18.0s (LMS Tech)"  'ACA-2010
  18.               aecBaseVer = "AecX.AecBaseApplication.6.0"
  19.  
  20.        Case "18.1s (LMS Tech)"  'ACA-2011
  21.               aecBaseVer = "AecX.AecBaseApplication.6.5"
  22.  
  23.        Case "18.2s (LMS Tech)"  'ACA-2012
  24.               aecBaseVer = "AecX.AecBaseApplication.6.7"
  25.  
  26.        Case "19.0s (LMS Tech)"  'ACA-2013
  27.               aecBaseVer = "AecX.AecBaseApplication.7.0"
  28.  
  29.        Case "19.1s (LMS Tech)"  'ACA-2014
  30.               aecBaseVer = "AecX.AecBaseApplication.7.5"
  31.  
  32.        Case Else
  33.                aecBaseVer = "Unknown"
  34.  
  35. End Select
  36.  
  37. If aecBaseVer = "Unknown" Then
  38.        RESULT = "Unknown Version"
  39.  
  40. Else
  41.  
  42.        ' Get a utility object to convert the Vector3D to an Array
  43.       Set aecBase = acadApp.GetInterfaceObject(aecBaseVer)
  44.        aecBase.Init acadApp
  45.        Set DuctFittingObject = acadApp.ActiveDocument.ObjectIDToObject([ObjectID])
  46.        Set UtilityObject = aecBase.ActiveDocument.Utility
  47.  
  48.        ' Get the Normal of the Object and break down into individual X, Y, and Z parts
  49.       DuctFittingObjectNormal = UtilityObject.ConvertToVariantArray(DuctFittingObject.Normal)
  50.        NormalX = DuctFittingObjectNormal(0)
  51.        NormalY = DuctFittingObjectNormal(1)
  52.        NormalZ = DuctFittingObjectNormal(2)
  53.  
  54.        'Return the results
  55.       RESULT = CStr(NormalX & ":" & NormalY & ":" & NormalZ)
  56.  
  57. End If
  58.  

By getting this information in the property set I can develop a display theme that will highlight any fittings that are upside down all through the user interface provided by Autocad Architecture and Autocad MEP.  Thanks again!
« Last Edit: March 09, 2013, 11:16:34 AM by Keith Brown »
Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013

fixo

  • Guest
Re: Autocad MEP - VBScript - get Normal of an Object
« Reply #4 on: March 10, 2013, 01:45:33 AM »
Glad you got it to work
Cheers :)