Author Topic: AutoCAD MEP: Convert .Net code to vba or more precisly vbscript  (Read 1871 times)

0 Members and 1 Guest are viewing this topic.

Keith Brown

  • Swamp Rat
  • Posts: 601
AutoCAD MEP: Convert .Net code to vba or more precisly vbscript
« on: December 26, 2013, 10:20:38 AM »
I have a piece of code in .net that I use to display the routing preference of a piece of duct in AutoCAD MEP.
 
Code - C#: [Select]
  1.  
  2.  if ((member.ObjectId.ObjectClass.Name == "AecbDbDuct") && (blockName.Text == "Routing Preference"))
  3.  {
  4.        using (Transaction transaction = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction())
  5.        {
  6.              Duct duct = new Duct();
  7.              duct = (Duct)member;
  8.              ObjectId objectId = duct.RoutingPreferenceId;
  9.               var obj = transaction.GetObject(objectId, OpenMode.ForRead) as DuctPartCatalogPreferenceStyle;
  10.               blockValue.Text = obj.Name;
  11.               transaction.Commit();
  12.         }
  13. }
  14.  

I use this code to display the routing preference of ductwork in a tooltip because out of the box the routing preference is not available as an automatic property definition.  I am wondering if anyone has done anything like this using VBA or vbscript.  I have done hooked into VBA in a property definition before using something like the below code.
 
Code - Text: [Select]
  1. On Error Resume Next
  2. DecimalPlaces = 3
  3. Set acadApp = GetObject(,"AutoCAD.Application")
  4.  
  5. 'ACADVER values:
  6. 'ACA 2010 = "18.0s (LMS Tech)"
  7. 'ACA 2011 = "18.1s (LMS Tech)"
  8. 'ACA 2012 = "18.2s (LMS Tech)"
  9. 'ACA 2013 = "19.0s (LMS Tech)"
  10. 'ACA 2014 = "19.1s (LMS Tech)"  'ACA 2015 = "19.2s (LMS Tech)"
  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 "19.2s (LMS Tech)"  'ACA-2015
  33.     aecBaseVer = "AecX.AecBaseApplication.7.7"
  34.  
  35.  Case Else
  36.     aecBaseVer = "Unknown"
  37. End Select
  38.  
  39. If aecBaseVer = "Unknown" Then
  40.    RESULT = "Unknown Version"
  41. Else
  42.    Set aecBase = acadApp.GetInterfaceObject(aecBaseVer)
  43.    aecBase.Init acadApp
  44.    Set DuctFittingObject = acadApp.ActiveDocument.ObjectIDToObject([ObjectID])
  45.    Set UtilityObject = aecBase.ActiveDocument.Utility
  46.  
  47.    ' Get the Normal of the Object and break down into individual X, Y, and Z parts
  48.    DuctFittingObjectNormal = UtilityObject.ConvertToVariantArray(DuctFittingObject.Normal)
  49.    NormalX = Round(DuctFittingObjectNormal(0), DecimalPlaces)
  50.    NormalY = Round(DuctFittingObjectNormal(1), DecimalPlaces)
  51.    NormalZ = Round(DuctFittingObjectNormal(2), DecimalPlaces)
  52.    
  53.    'Return the results
  54.    RESULT = CStr(NormalX & ";" & NormalY & ";" & NormalZ)
  55. End If

I know its a pretty obscure question but any help would be appreciated.
 
Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013