Can not finish edit part in assembly by code

Can not finish edit part in assembly by code

ngocson8335
Advocate Advocate
449 Views
2 Replies
Message 1 of 3

Can not finish edit part in assembly by code

ngocson8335
Advocate
Advocate

Dear Experts,

 

Please help me. Now I can calculate the stock number for parts in the context Assembly. But I have a problem is I can not finish edit part in assembly by code.

 

Can you suggest me another way that no need to edit part in the context ass, please?

 

Here is the code:

 

 

Imports System
Imports System.Runtime.InteropServices
Imports Inventor

Public Class Form1

Dim invApp As Inventor.Application
Dim partDoc As Inventor.PartDocument
Dim assemblyDoc As Inventor.AssemblyDocument

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

invApp = Marshal.GetActiveObject("Inventor.Application")


assemblyDoc = invApp.ActiveEditDocument
Dim assemblyDef As Inventor.AssemblyComponentDefinition
assemblyDef = assemblyDoc.ComponentDefinition

Dim oComponentOccurrence As Inventor.ComponentOccurrence
For Each oComponentOccurrence In assemblyDef.Occurrences


Dim oBox As Inventor.Box
oBox = oComponentOccurrence.RangeBox

Dim dmax As Point
dmax = oBox.MaxPoint

Dim dmin As Point
dmin = oBox.MinPoint

Dim dX As Decimal
Dim dY As Decimal
Dim dZ As Decimal

Dim strLength As Single
Dim strWidth As Single
Dim strThickness As Single

dX = (dmax.X - dmin.X) * 10
dY = (dmax.Y - dmin.Y) * 10
dZ = (dmax.Z - dmin.Z) * 10

Dim docPrec As Integer

dX = Math.Round(dX, docPrec)
dY = Math.Round(dY, docPrec)
dZ = Math.Round(dZ, docPrec)

Try

If dX = dY Then
strLength = dX
strWidth = dY
strThickness = dZ
End If

If dY = dZ Then
strLength = dX
strWidth = dZ
strThickness = dY

End If

If dX = dZ Then
strLength = dZ
strWidth = dY
strThickness = dX
End If

If dX > dY And dX > dZ Then
strLength = dX
If dY > dZ Then
strWidth = dY
strThickness = dZ
Else
strWidth = dZ
strThickness = dY
End If

End If
Catch ex As Exception

End Try

If dY > dX And dY > dZ Then
strLength = dY
If dX > dZ Then
strWidth = dX
strThickness = dZ
Else
strWidth = dZ
strThickness = dX
End If
End If

If dZ > dX And dZ > dY Then
strLength = dZ
If dX > dY Then
strWidth = dX
strThickness = dY
Else
strWidth = dY
strThickness = dX
End If
End If

MsgBox("Stock Number of " & oComponentOccurrence.Name & "is: " & strLength & " mm x " & strWidth & " mm x " & strThickness & " mm")

oComponentOccurrence.Edit()


Dim length As [Property]
Dim dimensiondirty As Boolean = False

partDoc = invApp.ActiveEditDocument

 

Try
length = partDoc.PropertySets.Item("User Defined Properties").Add("", "Length")

If Not length.Expression = strLength & " mm" Then

length.Expression = strLength & " mm"
dimensiondirty = True
End If


Catch ex As Exception

length = partDoc.PropertySets.Item("User Defined Properties").Item("Length")

If Not length.Expression = strLength & " mm" Then

length.Expression = strLength & " mm"
dimensiondirty = True
End If

End Try

'...

Next

End Sub


Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

End Sub

End Class

 

Thank you so much

 

Ngoc Son

Inventor's User

Ngoc Son
Autodesk User
0 Likes
Accepted solutions (1)
450 Views
2 Replies
Replies (2)
Message 2 of 3

marcin_otręba
Advisor
Advisor
Accepted solution

try:

 

For Each oComponentOccurrence In assemblyDef.Occurrences

oComponentOccurrence.Edit

 

oComponentOccurrence.ExitEdit kExitToTop

next

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

Message 3 of 3

ngocson8335
Advocate
Advocate

I fixed this problem.

 

Thank you so much.

 

Ngoc Son
Autodesk User
0 Likes