excel reading in ilogic code

excel reading in ilogic code

Anonymous
Not applicable
1,137 Views
10 Replies
Message 1 of 11

excel reading in ilogic code

Anonymous
Not applicable

Hi,

in the below code, in loop condition, two excel files are readen but it gives me error for second loop and stop. It just work for second loop...

Any one has any idea??

Sub Main()
GoExcel.Open(ThisDoc.Path & "\" & "Nozzles.xlsx", "Sheet1")
kk=1
For j=1 To 10
GoExcel.FindRowStart = kk+1
i = GoExcel.FindRow(ThisDoc.Path & "\" & "Nozzles.xlsx", "Sheet1", "RadialNozzle", "=", "true","class","=",150,"flangeType","=",0)
If i<>-1 Then
kk=i
aa= GoExcel.CurrentRowValue("nominalDiameter")
MessageBox.Show("Message"  & aa, "Title")
MessageBox.Show("Message"  & kk, "Title")
Dim sFilePath As String= ThisDoc.Path & "\"
ThisDoc.Save
doc = ThisDoc.Document
sNewName=GoExcel.CellValue("B" & i)
'GoExcel.Close'Next j'GoExcel.Open("C:\Users\Ali Khakbaz\Desktop\nozzle\WNFLG2.xlsx", "Sheet1")'i = GoExcel.FindRow("C:\Users\Ali Khakbaz\Desktop\nozzle\WNFLG2.xlsx", "Sheet1", "NPS", "=", aa)
i = GoExcel.FindRow(ThisDoc.Path & "\" & "WNFLG2.xlsx", "Sheet1", "NPS", "=", aa)
MessageBox.Show("Message"  & i-1, "Title",MessageBoxButtons.OK)
Lenght=  GoExcel.CurrentRowValue("O")
RuleParametersOutput()
GoExcel.Close
ThisDoc.Document.Update()
ThisDoc.Document.saveas(sFilePath & sNewName & ".ipt",True)
End If
Next j
ThisApplication.ActiveView.Fit
End Sub

Capture.PNG 

0 Likes
Accepted solutions (1)
1,138 Views
10 Replies
Replies (10)
Message 2 of 11

danijel.radenkovic
Collaborator
Collaborator

Can you provide a part and related excel docs?

 

Regards

Danijel

Inventor 2018/Windows 10 x64
If this information was helpful, please consider marking it as an Accepted Solution by using the Accept as Solution. Kudos are also gladly accepted.
0 Likes
Message 3 of 11

Anonymous
Not applicable

two excel files and part file are attached...

any other information that's needed, is possible for me to send..

i'm waiting for any idea

Thank you

0 Likes
Message 4 of 11

danijel.radenkovic
Collaborator
Collaborator

false.png

Hope this will help you.

Danijel

Inventor 2018/Windows 10 x64
If this information was helpful, please consider marking it as an Accepted Solution by using the Accept as Solution. Kudos are also gladly accepted.
0 Likes
Message 5 of 11

Anonymous
Not applicable
it did not change anything
for the first loop(J=1) it works but for J=2 it give me error, it seems that when it open the other excel and close that, it can not read first excel file
0 Likes
Message 6 of 11

Owner2229
Advisor
Advisor
Accepted solution

Hi, you've had "GoExcel.Close" in the "For..." loop, so it closed the excel after first cycle.

I have also moved some of your declarations out of the loop, because it doesn't need to be there and it's only slowing it's performance.

 

Sub Main()
Dim oDoc As Document = ThisDoc.Document
Dim sFilePath As String = ThisDoc.Path & "\"
GoExcel.Open(ThisDoc.Path & "\" & "Nozzles.xlsx", "Sheet1")
Dim kk As Double = 1
For j = 1 To 10
	GoExcel.FindRowStart = kk+1
	Dim i As Double = GoExcel.FindRow(ThisDoc.Path & "\" & "Nozzles.xlsx", "Sheet1", "RadialNozzle", "=", "true","class","=",150,"flangeType","=",0)
	If i <> -1 Then
		kk = i
		Dim aa As Double = GoExcel.CurrentRowValue("nominalDiameter")
		MessageBox.Show("Message " & aa & vbLf & "Message " & kk, "Title")
		oDoc.Save
		sNewName = GoExcel.CellValue("B" & i)
		'GoExcel.Close'Next j'GoExcel.Open("C:\Users\Ali Khakbaz\Desktop\nozzle\WNFLG2.xlsx", "Sheet1")'i = GoExcel.FindRow("C:\Users\Ali Khakbaz\Desktop\nozzle\WNFLG2.xlsx", "Sheet1", "NPS", "=", aa)
		i = GoExcel.FindRow(ThisDoc.Path & "\" & "WNFLG2.xlsx", "Sheet1", "NPS", "=", aa)
		MessageBox.Show("Message"  & i-1, "Title",MessageBoxButtons.OK)
		Parameter("Lenght") = GoExcel.CurrentRowValue("O")
		RuleParametersOutput()
		ThisDoc.Document.Update()
		ThisDoc.Document.saveas(sFilePath & sNewName & ".ipt", True)
	End If
Next j
GoExcel.Close
ThisApplication.ActiveView.Fit
End Sub
Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
Message 7 of 11

Anonymous
Not applicable

I ADDED drawing rules in the below of the code to save one drawing files of all this parts which was created

but it gives me errorCapture.PNG 

0 Likes
Message 8 of 11

Anonymous
Not applicable

it's my modified code

why does it happen?

Sub Main()
Dim oDoc As Document = ThisDoc.Document
Dim sFilePath As String = ThisDoc.Path & "\"
GoExcel.Open(ThisDoc.Path & "\" & "Nozzles.xlsx", "Sheet1")
Dim kk As Double = 1
For j = 1 To 10
    GoExcel.FindRowStart = kk+1
    Dim i As Double = GoExcel.FindRow(ThisDoc.Path & "\" & "Nozzles.xlsx", "Sheet1", "RadialNozzle", "=", "true","class","=",150,"flangeType","=",0)
    If i <> -1 Then
        kk = i
        Dim aa As Double = GoExcel.CurrentRowValue("nominalDiameter")
        MessageBox.Show("Message " & aa & vbLf & "Message " & kk, "Title")
        oDoc.Save
        sNewName = GoExcel.CellValue("B" & i)
        'GoExcel.Close'Next j'GoExcel.Open("C:\Users\Ali Khakbaz\Desktop\nozzle\WNFLG2.xlsx", "Sheet1")'i = GoExcel.FindRow("C:\Users\Ali Khakbaz\Desktop\nozzle\WNFLG2.xlsx", "Sheet1", "NPS", "=", aa)
        i = GoExcel.FindRow(ThisDoc.Path & "\" & "WNFLG2.xlsx", "Sheet1", "NPS", "=", aa)
        MessageBox.Show("Message"  & i-1, "Title",MessageBoxButtons.OK)
        Parameter("Lenght") = GoExcel.CurrentRowValue("O")
        RuleParametersOutput()
        ThisDoc.Document.Update()
        ThisDoc.Document.saveas(sFilePath & sNewName & ".ipt", True)
        dwgQuery = MsgBox("Would you like to Create a drawing for this Nozzle&Flange?", vbYesNo,"Drawing Selection")
        If dwgQuery = vbYes Then
        oDrawingDoc = ThisApplication.Documents.Add(kDrawingDocumentObject, "Test.idw",True)
        oSheet = oDrawingDoc.Sheets.Item(1)
        xDoc = ThisApplication.Documents.Open(sFilePath & sNewName & ".ipt", False)
        oPoint1 = ThisApplication.TransientGeometry.CreatePoint2d(5*?(i-1), 5)
        oView1 = oSheet.DrawingViews.AddBaseView(xDoc, _
        oPoint1, _
        1/1#, _
        kBottomViewOrientation, _
        kHiddenLineDrawingViewStyle)
        oView1 = oSheet.DrawingViews.Item(i-1)
        oView1.RotateByAngle(90*(PI / 180), False)
'        X=oSheet.Height/2'        Y=oSheet.Width/2'        ActiveSheet.View("oView1").SetCenter(X, Y)
        xDoc.Close(True)
        End If
        End If
    Next j
    GoExcel.Close
    ThisApplication.ActiveView.Fit
End Sub
0 Likes
Message 9 of 11

Owner2229
Advisor
Advisor
Sub Main()
Dim oDoc As Document = ThisDoc.Document
Dim sFilePath As String = ThisDoc.Path & "\"
GoExcel.Open(ThisDoc.Path & "\" & "Nozzles.xlsx", "Sheet1")
Dim kk As Double = 1
For j = 1 To 10
	GoExcel.FindRowStart = kk+1
	Dim i As Double = GoExcel.FindRow(ThisDoc.Path & "\" & "Nozzles.xlsx", "Sheet1", "RadialNozzle", "=", "true","class","=",150,"flangeType","=",0)
	If i <> -1 Then
		kk = i
		Dim aa As Double = GoExcel.CurrentRowValue("nominalDiameter")
		MessageBox.Show("Message " & aa & vbLf & "Message " & kk, "Title")
		oDoc.Save
		sNewName = GoExcel.CellValue("B" & i)
		i = GoExcel.FindRow(ThisDoc.Path & "\" & "WNFLG2.xlsx", "Sheet1", "NPS", "=", aa)
		MessageBox.Show("Message"  & i-1, "Title",MessageBoxButtons.OK)
		Parameter("Lenght") = GoExcel.CurrentRowValue("O")
		RuleParametersOutput()
		ThisDoc.Document.Update()
		ThisDoc.Document.saveas(sFilePath & sNewName & ".ipt", True)
		dwgQuery = MsgBox("Would you like to Create a drawing for this Nozzle&Flange?", vbYesNo,"Drawing Selection")
		If dwgQuery = vbYes Then
		    Dim oDrawingDoc As DrawingDocument = ThisApplication.Documents.Add(kDrawingDocumentObject, "Test.idw",True)
		    oSheet = oDrawingDoc.Sheets.Item(1)
       		    xDoc = ThisApplication.Documents.Open(sFilePath & sNewName & ".ipt", False)
        	    oPoint1 = ThisApplication.TransientGeometry.CreatePoint2d(5, 5)
        	    oView1 = oSheet.DrawingViews.AddBaseView(xDoc, _
        	    oPoint1, _
        	    1/1#, _
        	    kBottomViewOrientation, _
        	    kHiddenLineDrawingViewStyle)
        	    oView1 = oSheet.DrawingViews.Item(1)
        	    oView1.RotateByAngle(90*(PI / 180), False)
        	    xDoc.Close(True)
		End If
	End If
Next j
GoExcel.Close
ThisApplication.ActiveView.Fit
End Sub
Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes
Message 10 of 11

Anonymous
Not applicable
it still gives me the same error
just open a drawing file in first loop without no drawing...
furthermore i think due to i want all drawing files in one drawing file, it should be as previous your suggestion as below
Dim oSaveName As String = sFilePath & ThisDoc.FileName(False) & ".idw"
oDrawingDoc.SaveAs(oSaveName, False)
0 Likes
Message 11 of 11

Anonymous
Not applicable
am I right?
I think the problem is due to this line is in loop..
Dim oDrawingDoc As DrawingDocument = ThisApplication.Documents.Add(kDrawingDocumentObje​ct, "Test.idw",True)
what should I do?
I even try to save the sNewName in array list and then write this drawing codes but can't
0 Likes