making a step from a iPart/iAssembly on a drawing level

making a step from a iPart/iAssembly on a drawing level

FeelGoodGirl
Advocate Advocate
360 Views
4 Replies
Message 1 of 5

making a step from a iPart/iAssembly on a drawing level

FeelGoodGirl
Advocate
Advocate

Hi,


To make the work easier, I wrote a piece of code to complete the entire process with 1 push of a button. This almost completely works. This is done at drawing level. It is then saves the file, a step and PDF are created and the file is checked in. Making a step is not going well.

 

If this is a model with 1 file it is no problem. Then the code works fine. However, we use iParts and iAssemblies within the company. Then my code doesn't work good anymore. It seems that then the last open model is used. To better explain what goes wrong, I also made this image. 

 

ymvdbosch_0-1661422900490.png

This is the code that i use now. I've only shown the step making here. The rest of the code doesn't apply to my problem.

 

' The code to make a step from a drawing

Sub Main

	'The save path for option 3
	SavePath = "C:\TEMP"

	'Name of the file
	Name = iProperties.Value("Project", "Stock Number")
	Rev = iProperties.Value("Project", "Revision Number")

	FileName = Name + "-" + Rev

	'SaveOption	
	SaveLocation = SavePath

	'Check the last sign for \
	CheckLastSign = Right(SaveLocation, 1)
	If CheckLastSign <> "\" Then
		SaveLocation = SaveLocation + "\"
	End If

	'Combine location and name 
	LocationFileName = SaveLocation + FileName

	'Get the model and make STEP
	Dim oModel As Document = ThisApplication.ActiveDocument.AllReferencedDocuments.Item(1)
	If oModel.DocumentType = DocumentTypeEnum.kPartDocumentObject Or _
		oModel.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
		'Make STEP
		ExportToSTEP(oModel, SaveLocation, LocationFileName)
	End If
End Sub

Sub ExportToSTEP(oModelDoc As Document, SaveLocation As String, LocationFileName As String)
	'Get the STEP translator add-in
	Dim oSTEP As TranslatorAddIn
	For Each oAddIn As ApplicationAddIn In ThisApplication.ApplicationAddIns
		If oAddIn.DisplayName = "Translator: STEP" Then
			oSTEP = oAddIn
		End If
	Next
	If IsNothing(oSTEP) Then
		MsgBox("STEP Translator Add-in not found.  Exiting.", vbCritical, "iLogic")
		Exit Sub
	End If

	'Create needed variables for translator
	oTO = ThisApplication.TransientObjects
	oContext = oTO.CreateTranslationContext
	oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
	oOptions = oTO.CreateNameValueMap
	oDataMedium = oTO.CreateDataMedium

	oDataMedium.FileName = LocationFileName + ".stp"

	If oSTEP.HasSaveCopyAsOptions(oModelDoc, oContext, oOptions) Then
		' Set application protocol.
		' 2 = AP 203 - Configuration Controlled Design
		' 3 = AP 214 - Automotive Design
		oOptions.Value("ApplicationProtocolType") = 3
		oOptions.Value("IncludeSketches") = True
		oOptions.Value("export_fit_tolerance") = .000393701 'minimum
		oOptions.Value("Author") = ThisApplication.GeneralOptions.UserName
		oOptions.Value("Authorization") = ""
		oOptions.Value("Description") = oModelDoc.PropertySets(3).Item("Description").Value
		oOptions.Value("Organization") = oModelDoc.PropertySets(2).Item("Company").Value
		Try
			oSTEP.SaveCopyAs(oModelDoc, oContext, oOptions, oDataMedium)
		Catch
			MsgBox("Export drawing model to STEP file failed.", vbExclamation, "Export to step error")
		End Try
	End If
End Sub

 

Hopefully it is clear what is going wrong and what I am trying to achieve. Does anyone know how I can fix this?

0 Likes
361 Views
4 Replies
Replies (4)
Message 2 of 5

WCrihfield
Mentor
Mentor

Hi @FeelGoodGirl.  I do not currently use iParts or iAssemblies, but I do have some ideas about this scenario.  I have a question first though.  Is there more than one model document being represented within your drawing document?  Is there more than one view of that model (or each model) within the drawing?  If there are other views of the model, are the other views representing other variations of that model...such as other iPart/iAssembly members of the same source iPart/iAssembly Factory?

 

I see that you are getting the 'model' document through the 'active' document's 'AllReferencedDocuments' first item.  In a situation like this, where there are multiple variations (members) of the same base model within the 'model' document,  I believe it may be best to get the 'model' document from a specific DrawingView.  If you need the exported model to match the exact variation being shown within a specific view, then the DrawingView object has a property called 'ActiveMemberName' which I believe is supposed to return the name of the iPart/iAssembly member variation that this view is currently showing/representing.  This will help us later to ensure we have the proper associated model for the export process.  Once we extract the basic 'model' Document object from the view, we will then need to work with it a bit to ensure we are working with that specific variation (member) that matches what the view was showing.  The Part & Assembly specific types of component definition objects have properties that will help us determine if the model is a 'factory' or 'member', and ways to switch to the one we want to export, if it doesn't match the view.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 5

FeelGoodGirl
Advocate
Advocate

Hi,

 

Thanks for your message.

 

I'll try to answer your question first. Only one part is placed on a drawing. Maybe in multiple views, but it's the same part.

 

In my code I'm now looking at the first model posted on the drawing. To be quite honest, I'm doing this because I don't know a better way to do it. I still have a lot to learn in the world of iLogic.

 

You're talking about 'ActiveMemberName'. I've tried to do something with this, but I can't. Do you happen to have an example of this being used? I tried to search online but without success. Hopefully you can help me out a bit.

0 Likes
Message 4 of 5

FeelGoodGirl
Advocate
Advocate

I haven't managed to solve this problem yet. Does anyone have an idea how I can solve this?

0 Likes
Message 5 of 5

jjstr8
Collaborator
Collaborator

It works fine for me.  Regardless of what member is active in the original iPart, it exports the correct member from the drawing view.  I don't know if this is always the case, but AllReferencedDocuments(1) is the selected member in the view and AllReferencedDocuments(2) is the original iPart.  My test drawing only had one view.  I suggest adding the following to verify that the document that you pass to the ExportToSTEP is the correct member.

 

Logger.Info(oModel.FullDocumentName)

 

0 Likes