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: 

Open existing idw and replace model from iam iLogic assembly.

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
achmidt
2030 Views, 8 Replies

Open existing idw and replace model from iam iLogic assembly.

Hi,

I`m pretty sure it is simple I just need a little help.

 

I have an iLogic assembly for 2 parts that make a stub up. Using form to configure it.

 

stub up configurator.png

 

Here is the rules that make magic:

 

1st one makes sure that user saves it as new assembly, runs automatically when iam file is open.

 

'AC 2014  Stub up assembly configurator

Dim SFD As New SaveFileDialog()
SFD.InitialDirectory=ThisDoc.Path
SFD.Filter = "*.iam files (*.iam)|*.iam|All files (*.*)|*.*"
SFD.FileName="XXXXXTSA001"

PN=iProperties.Value("Project", "Part Number")

If PN<>"iStubup sleeve MASTER"  Then 
	' do nothing 
Else
	MessageBox.Show("PLEASE SAVE IT AS DIFFERENT ASSEMBLY NUMBER, FORMAT [XXXXXTSA001], WHERE XXXXX IS JOB NUMBER", "WARNING",MessageBoxButtons.OK) 
	If SFD.ShowDialog()=DialogResult.OK Then
		ThisDoc.Document.SaveAs(SFD.FileName , False)
		iProperties.Value("Project", "Part Number")=ThisDoc.FileName(False) 'without extension
		iLogicForm.Show("CONFIGURATOR")
	End If
End If

 2nd code fires after user hits Apply or OK button on the form

 

'АЛЕКС ШМИДТ 2014 Stubup configurator

Imports System.Windows.Forms

Parameter("End1", "Width") = Width
Parameter("End1", "Height") = Height
Parameter("Side1", "Length") = Length
Parameter("Side1", "Height") = Height
Parameter("End1", "FlangeW") = FlangeW
Parameter("Side1", "FlangeW") = FlangeW
Parameter("End1", "ShThk") = ShThk
Parameter("Side1", "ShThk") = ShThk

iProperties.Value("Summary", "Title")=JobN & " STUB UP SLEEVE ASSEMBLY " & Length & """L X " & Width & """W X " & Height & """H"

Dim FBD As New FolderBrowserDialog()
FBD.SelectedPath=ThisDoc.WorkspacePath()

If FBD.ShowDialog()=DialogResult.ok Then
	Parameter("End1", "FilePath") = FBD.SelectedPath
	Parameter("End1", "FileName") = EndPN
	Parameter("Side1", "FilePath") = FBD.SelectedPath
	Parameter("Side1", "FileName") = SidePN
	
	iLogicVb.RunRule("End1", "Adjusting")
	iLogicVb.RunRule("Side1", "Adjusting")
	
	iLogicVb.UpdateWhenDone = True
	Component.Replace("End1", FBD.SelectedPath & "\" & EndPN & ".ipt", True)
	Component.Replace("Side1", FBD.SelectedPath & "\" & SidePN & ".ipt", True)
	
	' update  all
	iLogicVb.UpdateWhenDone = True
	'zoom all
	ThisApplication.ActiveView.Fit
End If

iLogicVb.RunRule("Area")

' ThE eNd

 Each ipt. "Side1", "End1" etc has an iLogic code that allowes to save it with a given in a form Part number.

 

'АЛЕКС ШМИДТ 2014
iProperties.Value("Project", "Creation Date") = Now user = ThisApplication.GeneralOptions.UserName iProperties.Value("Project", "Designer") = user iProperties.Value("Summary", "Author") = user iProperties.Value("Summary", "Title") = "END SLEEVE " & Width & " X " & Height iProperties.Value("Project", "Description")=iProperties.Value("Summary", "Title") If ShThk = 0.313 Then SheetMetal.SetActiveStyle("5/16"& Chr(34)) Else If ShThk = 0.25 Then SheetMetal.SetActiveStyle("1/4"& Chr(34)) Else If ShThk = 0.1345 Then SheetMetal.SetActiveStyle("10ga") Else If ShThk = 0.105 Then SheetMetal.SetActiveStyle("12ga") Else If ShThk = 0.1793 Then SheetMetal.SetActiveStyle("7ga") End If Try ThisDoc.Document.SaveAs(FilePath & "\" & FileName & ".ipt" , True) Catch Ex As exception ' do nothing End Try

 Everything works just great. 

 

I do have a master drawing, simple, 4 views with callouts and dim`s. 

 

What I want is to open that drawing in the background, save it as the same assembly number and replace reference with newly configured assembly.

 

How I have to make a call from an iam file ?

 

I can open drawing using:

 

ThisDoc.Launch("c:\Work12\Designs\PARTS\iLogic tank parts\Stubup sleeve\iStubup sleeve MASTER.idw")

 

I do have a code to replace reference, but this works only form idw..

 

doc = ThisDoc.Document 


Dim oFD As FileDescriptor 
 oFD = doc.ReferencedFileDescriptors(1).DocumentDescriptor.ReferencedFileDescriptor 
 oFD.ReplaceReference("C:\File Name.iam")
 doc.Update()

 Any help is apreciated.. Thanks.

 

 

 

Inventor Virtual Parts Addin

http://apps.exchange.autodesk.com/INVNTOR/en/Detail/Index?id=appstore.exchange.autodesk.com%3Avirtualpartsadd-in_windows32and64%3Aen
8 REPLIES 8
Message 2 of 9
rjay75
in reply to: achmidt

This is because when the rule is run it is trying to perform Replace reference on the document that called the rule.

 

To have it refer to the drawing file try this.

 

Dim dwgDoc As Document
dwgDoc = ThisApplication.Documents.Open("c:\Work12\Designs\PARTS\iLogic tank parts\Stubup sleeve\iStubup sleeve MASTER.idw")

Dim oFD As FileDescriptor 
oFD = dwgDoc.ReferencedFileDescriptors(1).DocumentDescriptor.ReferencedFileDescriptor 
oFD.ReplaceReference("C:\File Name.iam")
dwgDoc.Update()
Message 3 of 9
achmidt
in reply to: rjay75

Thank you! It works. 

That was one part of a puzzle :-).  

 

2nd is I need to push a command to the drawing from iam to  Save it As with the new assembly number. How should I do this?

 

or should I push the parameter with new file name to the drawing and fire rule in the drawing to save it using parameter from iam assembly ? 

 

Thank you in advance!

Alex.

Inventor Virtual Parts Addin

http://apps.exchange.autodesk.com/INVNTOR/en/Detail/Index?id=appstore.exchange.autodesk.com%3Avirtualpartsadd-in_windows32and64%3Aen
Message 4 of 9
rjay75
in reply to: achmidt

Dim asmDoc as Document
asmDoc = ThisApplication.Documents.Open("Asmdoc.iam")
asmDoc.SaveAs("NewAsmdoc.iam")
asmDoc.Close()

 This will just save the assembly file with a new name. You'd have to do the same for each componenent as well.

 

See this thread http://forums.autodesk.com/t5/Inventor-Customization/Run-Time-Error-91/td-p/4945930

 

Message 5 of 9
achmidt
in reply to: rjay75

Thank you. Yes I know this will save current iam as a new assembly.

What I need is to save idw with replaced reference as a new idw drawing with new name.

 

Thanks,

Alex

 

Inventor Virtual Parts Addin

http://apps.exchange.autodesk.com/INVNTOR/en/Detail/Index?id=appstore.exchange.autodesk.com%3Avirtualpartsadd-in_windows32and64%3Aen
Message 6 of 9
rjay75
in reply to: achmidt

It will be the same thing. On any document call the SaveAs method. So for the drawing it would be

 

dwgDoc.SaveAs("NewFileName.idw")

 

Message 7 of 9
achmidt
in reply to: rjay75

Thanks man! This is what I added to make it work. I appreciate your help.

 

Dim dwgDoc As Document
dwgDoc = ThisApplication.Documents.Open("c:\Work12\Designs\PARTS\iLogic tank parts\Stubup sleeve\iStubup sleeve MASTER.idw")
dwgDoc.SaveAs(ThisDoc.Path & "\" & ThisDoc.FileName(False) & ".idw", False)

Dim oFD As FileDescriptor
oFD = dwgDoc.ReferencedFileDescriptors(1).DocumentDescriptor.ReferencedFileDescriptor
oFD.ReplaceReference(ThisDoc.PathAndFileName(True))
dwgDoc.Update()
Inventor Virtual Parts Addin

http://apps.exchange.autodesk.com/INVNTOR/en/Detail/Index?id=appstore.exchange.autodesk.com%3Avirtualpartsadd-in_windows32and64%3Aen
Message 8 of 9
rjay75
in reply to: achmidt

Just check the document that you're changing the reference on. If you wanted to change it on the file that was saved make sure to open the new file.

 

Dim dwgDoc As Document

dwgDoc = ThisApplication.Documents.Open("c:\Work12\Designs\PARTS\iLogic tank parts\Stubup sleeve\iStubup sleeve MASTER.idw")
'Save File as new Document
dwgDoc.SaveAs(ThisDoc.Path & "\" & ThisDoc.FileName(False) & ".idw", False)
'Close Template
dwgDoc.Close()
'Open New file
dwgDoc = ThisApplication.Documents.Open(ThisDoc.Path & "\" & ThisDoc.FileName(False) & ".idw")

Dim oFD As FileDescriptor 
oFD = dwgDoc.ReferencedFileDescriptors(1).DocumentDescriptor.ReferencedFileDescriptor 
oFD.ReplaceReference(ThisDoc.PathAndFileName(True))
dwgDoc.Update()

 

Message 9 of 9
achmidt
in reply to: rjay75

Thank you! Good idea.

Inventor Virtual Parts Addin

http://apps.exchange.autodesk.com/INVNTOR/en/Detail/Index?id=appstore.exchange.autodesk.com%3Avirtualpartsadd-in_windows32and64%3Aen

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

Post to forums  

Autodesk Design & Make Report