Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
JelteDeJong
in reply to: WCrihfield

Hi,

I have a code that is working in Visual studio. But when i copy it to an iLogic rule it does not work for the 2e connector. it looks like your previous problem. the connector does not get selected. therefore executing the edit command does not work. (i left 2 msgboxes in the code that will help you see it.) Anyway im trying to get it to work for a couple of hours now and i realy need to get to bed. but here is what i have so far. Maby some one else is seeing why the 2e connector is not getting selected.

Public Class ThisRule

	'Private Shared docEvents As DocumentEvents
	Private busy As Boolean = False

	Sub Main()

		' Get the collection of control definitions.
		Dim oControlDefs As ControlDefinitions = ThisApplication.CommandManager.ControlDefinitions

		' check if this document is a part document
		If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kPartDocumentObject Then
			MessageBox.Show("The current document must be a part file", "Incorrect Document Type")
			Return
		End If

		'Enter the BIM Content environment
		ThisApplication.CommandManager.ControlDefinitions.Item("AEC_Exchange:Environment").Execute()

		'Access the Browser and Activate the "Bim Content" Browser Pane
		Dim oPartDoc As PartDocument = ThisDoc.Document
		Dim bps = oPartDoc.BrowserPanes
		Dim bimContentPane As BrowserPane = Nothing
		For Each BP As BrowserPane In bps
			' the name is case sensitive original it worked only accidentally (BIM should be with capital letters)
			'       ' i made the if statement case insensitive ;-)
			If BP.Name.Equals("Bim Content", StringComparison.InvariantCultureIgnoreCase) Then
				BP.Activate()
				bimContentPane = BP
			End If
		Next

		'Define the Appearance variables
		Dim oElecAppearance As Asset = oPartDoc.Assets.Item("Connection_Electrical")
		Dim oMechAppearance As Asset = oPartDoc.Assets.Item("Connection_Mechanical")
		Dim oPipeAppearance As Asset = oPartDoc.Assets.Item("Connection_Piping")

		'Define the BIM Component Information
		Dim oPartDocBIM As BIMComponent = oPartDoc.ComponentDefinition.BIMComponent

		'Check through each Face on the body and see if uses the special appearance.
		For Each oSrfBody As SurfaceBody In oPartDoc.ComponentDefinition.SurfaceBodies
			For Each oFace As Face In oSrfBody.Faces
				If oFace.Appearance.DisplayName = oElecAppearance.DisplayName Then

					Dim Elec_Coll As ObjectCollection
					Elec_Coll = ThisApplication.TransientObjects.CreateObjectCollection
					Elec_Coll.Add(oFace)

					'Create Electrical Connector Definition
					Dim oElecConn As BIMElectricalConnectorDefinition

					oElecConn = oPartDocBIM.Connectors.CreateElectricalConnectorDefinition(Elec_Coll)
					oElecConn.SystemType = BIMElectricalSystemTypeEnum.kPowerBalancedElectricalSystemType

					'Add the Electrical BIM Connection
					Dim con As BIMConnector = oPartDocBIM.Connectors.Add(oElecConn)
					con.Name = "Elec_Conn_" & oPartDocBIM.Connectors.Count
					'Create a Browser Node and select the new connector via the Browser
					Dim oTopBrowserNode As BrowserNode = bimContentPane.TopNode
					For Each oNode As BrowserNode In oTopBrowserNode.BrowserNodes
						If Right(oNode.FullPath, 22) = "MEP System Connections" Then
							oNode.Expanded = True '<-- this is an important change
							Dim oSubNode As BrowserNode = oNode.BrowserNodes.Item(5)
							oSubNode.Expanded = True '<-- this is an important change
							Dim oConnNode As BrowserNode = oSubNode.BrowserNodes.Item(con.Name)
MsgBox("before select")
							oConnNode.DoSelect()
msgbox("After select")
							'Open and edit the new Electrical BIM Connector
							Dim oControlDef As ControlDefinition = oControlDefs.Item("AEC_Exchange:Command:Connector:Edit")

							' Execute the command.
							oControlDef.Execute()

							Dim docEvents As DocumentEvents = ThisApplication.ActiveDocument.DocumentEvents
							AddHandler docEvents.OnChange, AddressOf docEvents_OnChange
							busy = True
							While (busy = True)
								System.Threading.Thread.Sleep(50)
								ThisApplication.UserInterfaceManager.DoEvents()
							End While
							RemoveHandler docEvents.OnChange, AddressOf docEvents_OnChange

						End If
					Next

				End If
			Next
		Next
	End Sub


	Private Sub docEvents_OnChange(ReasonsForChange As CommandTypesEnum, BeforeOrAfter As EventTimingEnum, Context As NameValueMap, ByRef HandlingCode As HandlingCodeEnum)

		If (BeforeOrAfter = EventTimingEnum.kAfter And Context(1) = "API Change") Then
			busy = False
		End If

	End Sub

End Class

 

Jelte de Jong
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.

EESignature


Blog: hjalte.nl - github.com