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: 

Ilogic Save As not working

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
acanx21
670 Views, 2 Replies

Ilogic Save As not working

I created a Do until loop that will run through and make all my parts for me, while reading the parameters for each part from excel. I have the user input the values in the attached pictures before running the rule. My problem is that even though it correctly reads in the parameters from excel, and i've put in message boxes to show me that the parameters are correct throughout the rule, when the part gets to the save as, it only saves out the template. So even though throughout the creation of part 1, the width shows up as 20, when I open the part afterwards, the width is back to being 50. 

 

Before I had it set up so that instead of having a do until loop it would bring up the save as dialog with the next name on the list and all I had to do was hold down the enter key until all the parts were made. That worked, but I was really hoping to automate it so that I could be working on other things while this ran.

 

This is the excel it is reading from:

 image.png

 

SyntaxEditor Code Snippet

Sub Main()
Dim row As Integer = 3 'the 2nd row in excel is the template information
Dim CellVal As String = "Part"

GoExcel.Open(ExcelFile, SheetName)

Dim path As String = ThisDoc.Path & "\"

Do Until CellVal = ""
    Dim columnLetter As String = "A"
    CellVal = GoExcel.CellValue(columnLetter & row)
    If CellVal = "" Then Exit Do
    ReadExcel(CellVal) 'read the excel value
    InventorVb.DocumentUpdate() 'update part to show new values
    SaveAsNew(CellVal) 'save as part with new name
    row=row+1
Loop

End Sub

Function ReadExcel(CellVal)
'this function reads in the values from excel
i = GoExcel.FindRow(ExcelFile, SheetName, "Part", "=", CellVal) 'find the row with the part name
'get values corresponding to that part name Width = GoExcel.CurrentRowValue("Width") Left_Angle = GoExcel.CurrentRowValue("Left Angle") Right_Angle = GoExcel.CurrentRowValue("Right Angle") iLogicVb.UpdateWhenDone = True
ThisDoc.Save End Function Function SaveAsNew(CellVal) Dim newname As String newname = NewPath & CellVal InventorVb.DocumentUpdate() ThisDoc.Save ThisDoc.Document.SaveAs(newname & ".ipt", True) End Function

 

2 REPLIES 2
Message 2 of 3
MechMachineMan
in reply to: acanx21

Try something like this instead:

 

Sub Main()
	Dim row As Integer = 3 'the 2nd row in excel is the template information
	Dim CellVal As String = "Part"
	
	GoExcel.Open(ExcelFile, SheetName)
	
	oActiveDoc = ThisDoc.Document
	Dim path As String = oActiveDoc.Path & "\"
	
	Dim columnLetter As String = "A"
	CellVal = GoExcel.CellValue(columnLetter & row)
	
	Do Until CellVal = ""
		GeneratenewFile(CellVal) 'read the excel value
		row=row+1
		CellVal = GoExcel.CellValue(columnLetter & row)
	Loop

End Sub

Dim oActiveDoc As Document

	Sub GenerateNewFile(CellVal)
		'this function reads in the values from excel
		
		i = GoExcel.FindRow(ExcelFile, SheetName, "Part", "=", CellVal) 'find the row with the part name
		
		'get values corresponding to that part name
		oActiveDoc.ComponentDefinition.Paramters("Width").Expression = GoExcel.CurrentRowValue("Width")
		oActiveDoc.ComponentDefinition.Paramters("Left_Angle").Expression = GoExcel.CurrentRowValue("Left Angle")
		oActiveDoc.ComponentDefinition.Paramters("Right_Angle").Expression = GoExcel.CurrentRowValue("Right Angle")
		
		iLogicVb.UpdateWhenDone = True
		InventorVb.DocumentUpdate()
		oActiveDoc.SaveAs(NewPath & CellVal & ".ipt", True)
	End Sub

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
Message 3 of 3
acanx21
in reply to: MechMachineMan

Thank you! Your code worked for the first one but then not for the rest. I used some of the code you had written to modify mine though and now it works. The code ended up being this:

 

SyntaxEditor Code Snippet

Sub Main()
Dim row As Integer = 3
Dim CellVal As String = "Part"

GoExcel.Open(ExcelFile, SheetName)

Dim path As String = ThisDoc.Path & "\"

Do Until CellVal = ""
    Dim columnLetter As String = "A"
    CellVal = GoExcel.CellValue(columnLetter & row)
    If CellVal = "" Then Exit Do
    ReadExcel(CellVal)
    iLogicVb.UpdateWhenDone = True
    SaveAsNew(CellVal)
    row=row+1
Loop

End Sub

Function ReadExcel(CellVal)
i = GoExcel.FindRow(ExcelFile, SheetName, "Part", "=", CellVal)


ThisDoc.Document.ComponentDefinition.Parameters("Width").Expression = GoExcel.CurrentRowValue("Width")
ThisDoc.Document.ComponentDefinition.Parameters("Left_Angle").Expression = GoExcel.CurrentRowValue("Left Angle")
ThisDoc.Document.ComponentDefinition.Parameters("Right_Angle").Expression = GoExcel.CurrentRowValue("Right Angle")

iLogicVb.UpdateWhenDone = True
InventorVb.DocumentUpdate()
ThisDoc.Save

End Function 

Function SaveAsNew(CellVal)
Dim newname As String

newname = NewPath & CellVal

InventorVb.DocumentUpdate()
ThisDoc.Save
ThisDoc.Document.SaveAs(newname & ".ipt", True)

End Function

 

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

Post to forums  

Autodesk Design & Make Report