Hi guys,
This is actually my first post on this forum and I have just started VBA coding in Aecosim last week so bear with me.
I have managed to create a VBA code that will show the element ID at the center of the selected element(s) and it is working as intended. Now my problem is I am trying to extract the datagroup information from a compound cell (like a duct or an AHU) and put them in text files. I have searched everywhere online and read through the mechanical VBA code but with no luck. If someone could just, for an example, guide me through a code to extract the width and the height of a duct I would be grateful.
communities.bentley.com/.../105314;pi20068scroll=false
My code is as follow:-
Sub SelectionTest() Dim ee As ElementEnumerator Dim oElement As Element Dim mytext As TextElement Dim rotmatrix As Matrix3d Dim text As String Dim P As Point3d Dim extent As Point3d Dim range As Range3d Dim oParam As BMParameterSet Dim type1 As String If ActiveModelReference.AnyElementsSelected Then Set ee = ActiveModelReference.GetSelectedElements If ee Is Nothing Then MsgBox "ActiveModelReference.GetSelectedElements returned nothing" Else CadInputQueue.SendKeyin "textstyle active ""(ArialNarrow-1.8mm)""" Do While ee.MoveNext 'type1 = oParam.Get(bmdParameterGroupProperties, "CatalogName") Select Case ee.Current.Type Case msdElementTypeCellHeader 'Case msdElementTypeGroupData Set oElement = ee.Current.AsCellElement range = ee.Current.AsCellElement.range P.X = (range.High.X + range.Low.X) / 2 P.Y = (range.High.Y + range.Low.Y) / 2 P.Z = range.High.Z + 20 text = "ID = " & DLongToString(oElement.ID) 'Set mytext = CreateTextElement1(Nothing, type1, P, rotmatrix) Set mytext = CreateTextElement1(Nothing, text, P, rotmatrix) Application.ActiveModelReference.AddElement mytext 'Case msdElementTypeSharedCell
'MsgBox "Shared Cell Name = " & ee.Current.AsSharedCellElement.Name
'Case Else
'MsgBox "Not a cell - Element Type = " & CStr(ee.Current.Type)
End Select
Loop
End If
Else
MsgBox "No Elements selected"
End Sub
Best regards
Nayer
mark anderson [Bentley]
Visit me at https://communities.bentley.com/communities/other_communities/bentley_innovation/default.aspx
You can also use AECOsim Mechanical Component API to get parameters specific to AHU.
I did an example based on ABD SS6 Beta as below:
1. Reference AECOsim Mechanical Component API 3.0 Library in your VBA project;
2. Use the below code snippet:
Sub BBMS_ReadParameters() Dim oApp As New BMApplication Dim oElem As Element Dim oParamSet As BMParameterSet Set oElem = ActiveModelReference.GetElementByID(DLongFromLong(9948)) Set oParamSet = oApp.CreateParameterSetFromElement(oElem, True) MsgBox "CatalogType = " & oParamSet.CatalogType & vbCrLf & _ "CatalogItem = " & oParamSet.CatalogItem & vbCrLf & _ "CustomSchemaName = " & oParamSet.CustomSchemaName MsgBox "Custom Parameters:" & vbCrLf & _ " AHU Width = " & oParamSet.Get(bmdParameterGroupCustom, "AHUWidth") & vbCrLf & _ " AHU Height = " & oParamSet.Get(bmdParameterGroupCustom, "AHUHeight") & vbCrLf & _ " Total Length = " & oParamSet.Get(bmdParameterGroupCustom, "TotalLength") MsgBox "EndSpec1_1 Parameters:" & vbCrLf & _ " W1 = " & oParamSet.Get(bmdParameterGroupEndData, "End1/@width") & vbCrLf & _ " D1 = " & oParamSet.Get(bmdParameterGroupEndData, "End1/@depth") End Sub
3. Output results are as below:
HTH, YongAn
Answer Verified By: Nayer Girgis