Prompt Users to Select Face when Converting to Sheet Metal

Prompt Users to Select Face when Converting to Sheet Metal

evan.shimek
Participant Participant
698 Views
5 Replies
Message 1 of 6

Prompt Users to Select Face when Converting to Sheet Metal

evan.shimek
Participant
Participant

I've been attempting to write a code in VBA that cycles through all of the part files within my derived assemblies, gives you the option to convert them to sheet metal and then prompts the user to select a face, similar to the built-in sheet metal command.

 

Does anyone have a good way of achieving this?

 

I should also mention that I've attempted the automated ray-tracing method from Mod the Machine, but while it works beautifully when it works, it seems to struggle finding the thickness for about a third of my plates. So, I intend to run this variation when an error occurs.

0 Likes
Accepted solutions (1)
699 Views
5 Replies
Replies (5)
Message 2 of 6

WCrihfield
Mentor
Mentor

Hi @evan.shimek.  If it is getting hung up on that line, that usually means that you have not pre-selected anything (specifically a component in this case) prior to running that macro.  If it is getting its input from the SelectSet of the 'active' document, then you must have selected something within that 'active' document before running that macro.  Just my initial thoughts.  Generally macro's will not be recognized as a macro that can be ran by clicking a button in the ribbon if they are are asking for 'input variables', or if they are set-up as a Function (returns something) but since your main routine is a Sub, and is not set-up to receive an input variable(s), it might work OK as a button, but is an odd use for one.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 6

evan.shimek
Participant
Participant

Thank you, @WCrihfield. I have a better understanding of how this pasted code was intended to work, now. I think it's perhaps leading me down the wrong path. Really, all I'm looking for is something that will cycle through specific part files and initiate Inventor's built-in sheet metal command up until the point where it's asking the user to select the base plane. 

0 Likes
Message 4 of 6

WCrihfield
Mentor
Mentor
Accepted solution

Hi @evan.shimek.  I know how to convert regular parts to sheet metal parts by code, however doing so in a loop of many parts in an assembly, and pausing each time just long enough for you to manually select which face you want to be the base face, then somehow moving on to the next part, is another story.  You can convert a regular part into a sheet metal part by simply changing the value of its SubType property.  But the values needed are long, strings of letters and numbers, with no readable meaning, just used as unique identifiers, and have to be just right for it to work.  I also know how to interrupt a rule to allow for manual selection of a face, but I am not sure how to store the 'base face' choice.  That is usually not needed until you go to unfold the model into a flat pattern.  The FlatPattern object itself has a BaseFace property, but that doesn't exist yet until you create it, by unfolding the sheet metal part, if it is able to be unfolded.  When converting by code, the base face is usually not specified.  If a flat pattern is immediately needed, then you could use the Pick function to allow the user to manually select a face to use as the BaseFace just before using the Unfold2 method to create the FlatPattern object.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 5 of 6

evan.shimek
Participant
Participant

Thank you for your help. It sounds like I'm going down a bad path. I'll look towards alternative methods.

0 Likes
Message 6 of 6

WCrihfield
Mentor
Mentor

OK.  By the way...this is about as close as I can get to the solution you were asking for, but it is missing that final step of storing your selection of a Base Face to the document somehow.  I know that when you use the manual user interface tool to convert a regular part into a sheet metal part, it immediately asks you to manually select a base face.  But I honestly have not been able to figure out how or where they are storing that data.  I looked in Attributes.  I looked for a hidden property of the SheetMetalComponentDefinition called BaseFace, thinking it may just be hidden, but it was not found.  This might be a good question for someone who does the programming at Autodesk.

Here is the code...just for your reference, and for future possible further development.

If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
	MsgBox("An Assembly Document must be active for this rule to work. Exiting.", vbCritical, "")
	Exit Sub
End If
Dim oADoc As AssemblyDocument = ThisDoc.Document
Dim oRefDocs As DocumentsEnumerator = oADoc.AllReferencedDocuments
For Each oRefDoc As Document In oRefDocs
	'if it is a regular Part Then
	If oRefDoc.SubType = "{4D29B490-49B2-11D0-93C3-7E0706000000}" Then
		ThisApplication.Documents.Open(oRefDoc.FullDocumentName, True)
		Try
			'try to convert it to Sheet Metal Part
			oRefDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}"
		Catch
			Logger.Error("Error trying to convert following Part to Sheet Metal Part:" _
			& vbCrLf & oRefDoc.FullDocumentName)
			Continue For
		End Try
		Dim oBaseFace As Face = Nothing
		oBaseFace = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "Select Base Face.")
		If IsNothing(oBaseFace) Then Continue For
		'not sure how to store this selection to a property in the part or component definition
		'the FlatPatter object has a BaseFace property, but that object will not exist yet
		'I don't think it is stored in an Attribute either...maybe a hidden property
		'I already tried to store it to SheetMetalComponentDefinition.BaseFace, but that property does not exist
		If oRefDoc.RequiresUpdate Then oRefDoc.Update
		If oRefDoc.Dirty Then oRefDoc.Save
		oRefDoc.Close(True)
	End If
Next

Also, I do know the command that is behind the manual button.  It is called "PartConvertToSheetMetalCmd".  You can execute this command by code, but that just simulates you clicking the button.  In a loop of many parts in a code, I seriously doubt it would wait each time for you to select a base face, then continue to the next part immediately afterwards.  Sometimes using the user interface tools is simply better or does more than the available API code can in certain situations.  This may be one of those situations.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)