iLogic - Rule Automation / Breaking Points in Code

iLogic - Rule Automation / Breaking Points in Code

jhunt3Z5BG
Participant Participant
633 Views
6 Replies
Message 1 of 7

iLogic - Rule Automation / Breaking Points in Code

jhunt3Z5BG
Participant
Participant

I Used your solution (@JelteDeJong ) and inserted the concept in some code I was working on; some borrowed from @Anonymous. I attached the code in a text file and my excel data sheet.

 

The problems I am seeing are as follows:

  • When I have a qty of more than 1 it errors out
    • I Want to add more than 1 VC if there are more than 1 qty in the spreadsheet
  • When any of the cells are blank, it errors out
    • I want it to continue if they are blank, if possible
  • Is there a nifty way for the iLogic Program to automatically figure out how many cells to check in excel without me stating to check 2,000 rows, as these rows may change per spreadsheet?

 

 

I was wondering if you (@JelteDeJong ) or Curtis ( @Anonymous) might be able to assist. I think it is simple, I am just missing it.

 

 

 

0 Likes
Accepted solutions (1)
634 Views
6 Replies
Replies (6)
Message 2 of 7

JMGunnar
Collaborator
Collaborator

Here my solution 

if there write END in A column or A column is empty it exit

Best regards Johan G

 

For i = 2 To 2000
						If i = 2 Then
							
							occName = GoExcel.CellValue(ExcelPath, "Blad1", "A" & i)
							oFileName =  GoExcel.CellValue("B" & i)
							
						Else If GoExcel.CellValue("A" & i) = "END" Or String.IsNullOrEmpty(GoExcel.CellValue("A" & i))  Then
							Exit For
						Else
							Try
								
								occName = GoExcel.CellValue(ExcelPath, "Blad1", "A" & i)
								oFileName =  GoExcel.CellValue("B" & i)
						
							Catch
								Exit For
							End Try
						End If 
		Next

 

 

 

0 Likes
Message 3 of 7

jhunt3Z5BG
Participant
Participant

@JMGunnar  My apologies for the late response, I was in a training session all day. First of all thank you for your response. I went a different route. I did a simple if statement to solve one of my issues

	If oProp1 = Nothing Then
		oProp1 = " "
	End If

 I was able to also create a method to automate the data extents, along with creating some code for the user to select their spread sheet to use.

 

Outstanding Issue:

My only issue is when I have a qty 2 of any virtual component it errors out. It used to work, until I added code to add my custom iProperties to the VC's.

 

The code is in the main section of the attached code file (word Document). I grabbed this code from one of @Anonymous posts. It worked well until I added my custom iProperties. 

	'Dim index As Integer
	index = 2
	Do While index <= iQTY
		occs.AddByComponentDefinition(virtOcc.Definition, oMatrix)
		index += 1
	Loop

 

0 Likes
Message 4 of 7

JMGunnar
Collaborator
Collaborator
Accepted solution

I Change 

 

Do While index <= iQTY           

      occs.AddByComponentDefinition(virtOcc.Definition, oMatrix)           

      index += 1       

 Loop

 

too  - > 

 

Do While index <= iQTY

    odef = oCVirtualCompDef

   occs.AddByComponentDefinition(odef, oMatrix)

index += 1

Loop

 

Johan

 

 

Dim oCVirtualCompDef As VirtualComponentDefinition
	Dim oNewOcc As ComponentOccurrence 
	
	If iQTY >= 1 Then
		Dim PropertyName1 As String = "PN"
		Dim PropertyName2 As String = "NA"
		Dim PropertyName3 As String = "NB"
		 oNewOcc  = oAssDef.Occurrences.AddVirtual(sVirtPart, oMatrix)
		 oCVirtualCompDef  = oNewOcc.Definition
 '-----------------------------------------Population of Description iProperty
		Dim IDX As String = sVirtPart & ":"&index
			iProperties.Value(IDX, "Project", "Description") = oProp1	
			'iProperties.Value(sVirtPart & ":1", "Project", "Description") = oProp1	
'-----------------------------------------PN iProperty Creation & Population			
		Dim customSet = oCVirtualCompDef.PropertySets.Item("Inventor User Defined Properties")
		Try
		    Dim prop As [Property] = customSet.Item(PropertyName1)
		    prop.Value = oProp2
		Catch ex As Exception
		    customSet.Add(oProp2, PropertyName1)
		End Try
'-----------------------------------------FAMILY iProperty Creation & Population		
		Try
		    Dim prop As [Property] = customSet.Item(PropertyName2)
		    prop.Value = oProp3
		Catch ex As Exception
		    customSet.Add(oProp3, PropertyName2)
		End Try
'-----------------------------------------NUMB iProperty Creation & Population	
		Try
		    Dim prop As [Property] = customSet.Item(PropertyName3)
		    prop.Value = oProp4
		Catch ex As Exception
		    customSet.Add(oProp4, PropertyName3)
		End Try				
	End If
'-----------------------------------------Add the next instance starting at instance2 (if applicable)
	'Dim index As Integer
	index = 2
	
	
	
	
	Do While index <= iQTY
		
		odef = oCVirtualCompDef
		
		occs.AddByComponentDefinition(odef, oMatrix)
		index += 1
	Loop
Next

 

 

 

 

 

 

 

 

Message 5 of 7

jhunt3Z5BG
Participant
Participant

Any thoughts on the error message below when I entered in the code as prescribed?

 

 

jhunt3Z5BG_0-1660738173382.png

 

0 Likes
Message 6 of 7

JMGunnar
Collaborator
Collaborator

I have move  definition out

 

 

Dim oCVirtualCompDef As VirtualComponentDefinition

Dim oNewOcc As ComponentOccurrence 

 

 

If iQTY >= 1 Then

    oNewOcc = oAssDef.Occurrences.AddVirtual(sVirtPart, oMatrix)

    oCVirtualCompDef = oNewOcc.Definition

 

End If 

 

Message 7 of 7

jhunt3Z5BG
Participant
Participant

I see what you did now. I made the changes as you mentioned and I noticed a couple other items I missed. I see why you pushed it out now.

 

Thank you!

0 Likes