Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Pause for User Input Dialog Box - Not Quite Getting it Right

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
petestrycharske
1613 Views, 7 Replies

Pause for User Input Dialog Box - Not Quite Getting it Right

All,

 

Good morning!  I've been trying to automate the creation of some BIM Connectors and am tantalizingly close, but cannot quite seem to figure out how to properly pause the code to allow users to edit the connectors.  I've been playing with the .Execute2(False / True) command, but must be missing something.  Please see the video below and the attached part file and I would truly appreciate any suggestions that you have!  Full disclosure, I'm not a programmer, so feel free to poke fun at my code, which I already know I'll have to clean up.  Thanks  in advance for any help, hope all is well and have a most blessed day!

 

Peace,

Pete

Just a guy on a couch...

Please give a kudos if helpful and mark as a solution if somehow I got it right.
Labels (2)
7 REPLIES 7
Message 2 of 8

I expect the problem here is that the form is on a seperated thread. the only way i could think of to stop the main thread by creating a endless loop afther the execute command. and then look for document change events. And then break out of the loop if the event was triggered. I have some code to do this but the code is not working. Probably i forgot something small. My son just woke up so i have to take care of him. I will have a look at it later. Or maby some one else has a better solution.

 

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

Message 3 of 8

 Here is a link to something you may be able to use.

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 4 of 8

FYI

Here are also several other commands (ControlDefinition Names)  for AEC Exchange you might find some use for while working in that environment:

AEC_Exchange:Command:AuthorComponent                  Author Building Components
AEC_Exchange:Command:Connector:Add                    Add Connector
AEC_Exchange:Command:Connector:Cable                  Cable Tray Connector
AEC_Exchange:Command:Connector:Conduit                Conduit Connector
AEC_Exchange:Command:Connector:Delete                 Delete Connector(s)
AEC_Exchange:Command:Connector:Duct                   Duct Connector
AEC_Exchange:Command:Connector:Edit                   Edit Connector
AEC_Exchange:Command:Connector:Electrical             Electrical Connector
AEC_Exchange:Command:Connector:IncludeChildren        Promote Component Connectors
AEC_Exchange:Command:Connector:Link                   Link Connectors
AEC_Exchange:Command:Connector:Pipe                   Pipe Connector
AEC_Exchange:Command:Connector:Suppress               Suppress Connector(s)
AEC_Exchange:Command:Connector:Unlink                 Delete Link
AEC_Exchange:Command:QualityCheck                     Design Quality Check
AEC_Exchange:Command:ShareDesignPackage               Export Building Components
AEC_Exchange:Command:UploadToC360Wrapper              Upload to Configurator 360
AEC_Exchange:Environment                              
AEC_Exchange_Command_Include_Connector                Include Connector
AEC_Exchange_Command_Shrinkwrap                       Shrinkwrap Substitute
AEC_Exchange_Command_Source_Component                 Source Component

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 5 of 8
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

Message 6 of 8
JelteDeJong
in reply to: JelteDeJong

Hi, i found the problem that i had last knight. the command form was closed but the command it self was not finished. i had to force it to stop. That did the trick. Below you find the working code. I also removed some code that could that loops over all nodes tofind the correct Browserpane and nodes. (and i used my own code from you previous question;-)

Public Class ThisRule

	Private busy As Boolean = False

	Sub Main()

		' Get the collection of control definitions.
		Dim oControlDefs As ControlDefinitions = ThisApplication.CommandManager.ControlDefinitions
		Dim oControlDef As ControlDefinition = oControlDefs.Item("AEC_Exchange:Command:Connector:Edit")

		' 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 = oPartDoc.BrowserPanes.Item("AEC_Exchange:Browser")

		'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



					Dim systemNode As BrowserNode = bimContentPane.TopNode.BrowserNodes.Item("MEP System Connections")
					Dim electicalNode As BrowserNode = systemNode.BrowserNodes.Item("Electrical")
					electicalNode.Expanded = True
					Dim oConnNode As BrowserNode = electicalNode.BrowserNodes.Item(con.Name)
					oConnNode.DoSelect()

					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
					ThisApplication.CommandManager.StopActiveCommand()

				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

Message 7 of 8

@JelteDeJong, good morning!  That worked perfectly and I've now adapted it to work with piping and duct connectors!  I finally broke down and decided to use your code 🤣  Seriously though, I cannot thank you enough as this is now working the way that I envisioned it to.  I really appreciate the help, hope all is well and have a most blessed day!

 

Peace,

Pete

Just a guy on a couch...

Please give a kudos if helpful and mark as a solution if somehow I got it right.
Message 8 of 8

Its good that you have decided to use my code. I knew I could convince you to come to the dark side.

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report