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: 

Change KFactor with VBA

4 REPLIES 4
Reply
Message 1 of 5
rhutchins
832 Views, 4 Replies

Change KFactor with VBA

I have not been able to find any info on this any help would be awesome, al I want to do is change the KFactor of a current drawing or even add a new one and set it as default I tried using send keys but I can not seem to get to the Value box. reason for this I have a bunch of customer files that use .44 the default and for our shop .33 works almost perfect on everything it doesn't matter on parts with 1 or even 2 bends but something with 5 or 6 using 14 or 16 ga it really starts to matter so I am looking for a quick way to change the KFactor.

Thanks
bhutchins
4 REPLIES 4
Message 2 of 5
petercharles
in reply to: rhutchins

I think the trick is to create extra Sheet Metal Styles with the different K factors and then swap between them. I'm sure I wrote a macro to do this but I just can't remember where it is!
(Old age :-(( )
Message 3 of 5
rhutchins
in reply to: rhutchins

Well thanks I guess, I am pretty new to VBA and macros if you find your macro could you please post it.

I found this in the help file but I don't know how to use it I tried to copy it into a macro but I am lost.

Public Function AddLinearUnfoldMethod( _
ByVal Name As String, _
ByVal Value As String _
) As UnfoldMethod


Thanks,
bhutchins
Message 4 of 5
Anonymous
in reply to: rhutchins

Here's a small program that changes the kFactor for the active part. It
assumes that the active unfold method for the active sheet metal style is a
linear unfold method and changes the kFactor value associated with it.

Public Sub SetKFactor()
' Get the sheet metal component definition from the active document.
Dim oPartDoc As PartDocument
Set oPartDoc = ThisApplication.ActiveDocument
Dim oSheetMetalDef As SheetMetalComponentDefinition
Set oSheetMetalDef = oPartDoc.ComponentDefinition

' Get the active sheet metal style.
Dim oSheetMetalStyle As SheetMetalStyle
Set oSheetMetalStyle = oSheetMetalDef.ActiveSheetMetalStyle

' Get the active unfold method.
Dim oUnfoldMethod As UnfoldMethod
Set oUnfoldMethod = oSheetMetalStyle.ActiveUnfoldMethod

' Check to make sure it's a K Factor unfold method.
If oUnfoldMethod.UnfoldMethodType = kLinearUnfoldMethod Then
' Change the K Factor.
oUnfoldMethod.Value = 0.33

' Update the part.
oPartDoc.Update
End If
End Sub

--
Brian Ekins
Autodesk Inventor API
Message 5 of 5
petercharles
in reply to: rhutchins

Found it !!
This was done to toggle between Imperial and Metric plate thicknesses, but you can sort it out to do what you want...

Code follows, but check for any broken lines of code :-

Option Explicit

Public Sub ModStyle()

Dim oDoc As Document
Set oDoc = ThisApplication.ActiveDocument

If oDoc.SubType = "{E60F81E1-49B3-11D0-93C3-7E0706000000}" Then
Dim oFileRef As ReferencedFileDescriptor
For Each oFileRef In oDoc.ReferencedFileDescriptors
Call updateStyle(oFileRef.ReferencedDocument)
Next oFileRef
oDoc.Update
Exit Sub
End If

If oDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
Call updateStyle(oFileRef.ReferencedDocument)
oDoc.Update
Exit Sub
End If

End Sub

Public Sub updateStyle(fileRef)

Dim oDoc As Document
Set oDoc = fileRef

Dim oSheetMetalCompDef As SheetMetalComponentDefinition
Set oSheetMetalCompDef = oDoc.ComponentDefinition

Dim oStyle As SheetMetalStyle


If StrComp(UCase("0.25 Mild Steel"), UCase(oSheetMetalCompDef.ActiveSheetMetalStyle.Name), vbTextCompare) = 0 Then
For Each oStyle In oSheetMetalCompDef.SheetMetalStyles
If StrComp(UCase(oStyle.Name), UCase("6mm Mild Steel"), vbTextCompare) = 0 Then
oStyle.Activate
oDoc.Update
Exit Sub
End If
Next
End If

If StrComp(UCase("6mm Mild Steel"), UCase(oSheetMetalCompDef.ActiveSheetMetalStyle.Name), vbTextCompare) = 0 Then
For Each oStyle In oSheetMetalCompDef.SheetMetalStyles
If StrComp(UCase(oStyle.Name), UCase("0.25 Mild Steel"), vbTextCompare) = 0 Then
oStyle.Activate
oDoc.Update
Exit Sub
End If
Next
End If

If StrComp(UCase("0.1875 Mild Steel"), UCase(oSheetMetalCompDef.ActiveSheetMetalStyle.Name), vbTextCompare) = 0 Then
For Each oStyle In oSheetMetalCompDef.SheetMetalStyles
If StrComp(UCase(oStyle.Name), UCase("5mm Mild Steel"), vbTextCompare) = 0 Then
oStyle.Activate
oDoc.Update
Exit Sub
End If
Next
End If

If StrComp(UCase("5mm Mild Steel"), UCase(oSheetMetalCompDef.ActiveSheetMetalStyle.Name), vbTextCompare) = 0 Then
For Each oStyle In oSheetMetalCompDef.SheetMetalStyles
If StrComp(UCase(oStyle.Name), UCase("0.1875 Mild Steel"), vbTextCompare) = 0 Then
oStyle.Activate
oDoc.Update
Exit Sub
End If
Next
End If

If StrComp(UCase("0.1194 Mild Steel"), UCase(oSheetMetalCompDef.ActiveSheetMetalStyle.Name), vbTextCompare) = 0 Then
For Each oStyle In oSheetMetalCompDef.SheetMetalStyles
If StrComp(UCase(oStyle.Name), UCase("3mm Mild Steel"), vbTextCompare) = 0 Then
oStyle.Activate
oDoc.Update
Exit Sub
End If
Next
End If

If StrComp(UCase("3mm Mild Steel"), UCase(oSheetMetalCompDef.ActiveSheetMetalStyle.Name), vbTextCompare) = 0 Then
For Each oStyle In oSheetMetalCompDef.SheetMetalStyles
If StrComp(UCase(oStyle.Name), UCase("0.1194 Mild Steel"), vbTextCompare) = 0 Then
oStyle.Activate
oDoc.Update
Exit Sub
End If
Next
End If

End Sub

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

Post to forums  

Autodesk Design & Make Report