Changing flush constraint offset with VB.NET

Changing flush constraint offset with VB.NET

keithjk
Advocate Advocate
1,448 Views
6 Replies
Message 1 of 7

Changing flush constraint offset with VB.NET

keithjk
Advocate
Advocate

I want to be able to to change the offset of my flush constraints.  The code below is a start.  I can retrieve the current offset values of my two constraints and then post them to a text box.  But I cannot figure out how to send the data back from the text box when the user changes it.

 

 

 

Dim selSet As SelectSet

selSet = oAssemblyDocument.SelectSet

Dim selSetCount As Integer = 0

selSetCount = selSet.Count

If selSetCount = Nothing Or selSetCount = 0 Then

Beep()

MsgBox("You must select component(s) first.", vbOKOnly, "Error Selecting Components")

Else

 

If TypeOf selSet.Item(1) Is ComponentOccurrence Then

oOcc = selSet.Item(1)

'are there existing constraints?

If oOcc.Constraints.Count > 0 Then

For j = 1 To oOcc.Constraints.Count

'is there a mating constraint?

If UCase(oOcc.Constraints.Item(j).Name).Contains("FLUSH") = True Then

If j = 1 Then

Constraint1 = oOcc.Constraints.Item(j)

txtOffset1.Text = Math.Round((Constraint1.Offset.Value), 4)

End If

If j = 2 Then

Constraint2 = oOcc.Constraints.Item(j)

txtOffset2.Text = Math.Round((Constraint2.Offset.Value), 4)

End If

End If

Next j

End If

End If

End If

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

xiaodong_liang
Autodesk Support
Autodesk Support

Hi,

 

Offset is an object Parameter. you can set its value by Offset.Value =  <new value>.

 

hope it helps.

0 Likes
Message 3 of 7

keithjk
Advocate
Advocate

Xiaodong,


Thanks for the response.  My problem was that I failed to place ".value" after offset when I was trying to change it.  Now I have a new problem in that even though I can set the offset value, it does not update the componet in the assembly. 

 

For testing purposes, I am trying to add or subtract 0.75 units in the code below.  It accepts the new offset values now but it does not move the component.  And if I look at the properties of the constraint offset in Inventor (see attached) it isn't updating it.  To me it looks like I am not obtaining or setting the correct offset parameter?? (If that makes sense.).  I have verified that that I am trying to change the correct constraint.  I have also verfied that the component is not grounded.

 

Thanks for the help.  I am new to programming in Inventor.

 

Keith

 

 

Private Sub btnChangeComp_Click(sender As Object, e As EventArgs) Handles btnChangeComp.Click

selSet = oAssemblyDocument.SelectSet

Dim selSetCount As Integer = 0

selSetCount = selSet.Count

If selSetCount = Nothing Or selSetCount = 0 Then

Beep()

MsgBox("You must select component(s) first.", vbOKOnly, "Error Selecting Components")

Else

 

If TypeOf selSet.Item(1) Is ComponentOccurrence Then

oOcc = selSet.Item(1)

'are there existing constraints?

If oOcc.Constraints.Count > 0 Then

For j = 1 To oOcc.Constraints.Count

'is there a mating constraint?

If UCase(oOcc.Constraints.Item(j).Name).Contains("FLUSH") = True Then

If j = 1 Then

Constraint1 = oOcc.Constraints.Item(j)

txtOffset1.Text = Math.Round((Constraint1.Offset.Value), 4)

' /////////// this is just for testing ///////////////////

Constraint1.Offset.Value = Constraint1.Offset.Value - 0.75

End If

If j = 2 Then

Constraint2 = oOcc.Constraints.Item(j)

txtOffset2.Text = Math.Round((Constraint2.Offset.Value), 4)

' /////////// this is just for testing ///////////////////

Constraint2.Offset.Value = Constraint2.Offset.Value + 0.75

End If

End If

Next j

End If

End If

End If

End Sub

0 Likes
Message 4 of 7

MechMachineMan
Advisor
Advisor
Accepted solution

Have you tried simply updating/rebuilding the model after you change it?


--------------------------------------
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 5 of 7

keithjk
Advocate
Advocate
Accepted solution

updating the assembly did it!


Thanks!!!

0 Likes
Message 6 of 7

MechMachineMan
Advisor
Advisor
oAssemblyDocument.Update should work perfect to accomplish that in your program.

--------------------------------------
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
0 Likes
Message 7 of 7

xiaodong_liang
Autodesk Support
Autodesk Support
Hi keithjk,

I just got time to get back, while it looks Justin has helped you 🙂 I marked it as the solution.
0 Likes