VBA Code "update"

VBA Code "update"

gustavo.cassel
Advocate Advocate
306 Views
2 Replies
Message 1 of 3

VBA Code "update"

gustavo.cassel
Advocate
Advocate

Hi, i'm having a issue with some code, i'm trying to transform a sheetmetal part to his template and create the flatpattern. But when i test the subtype and try to convert it, it gives me an error on the next command. I've found a solution but i not like it, i made a  pop-up timeout windows form, to "update" the code and it can gets the definition on line 12. Could someone tell me what is going on?

Here is the example code:

#If Win64 Then
    Private Declare PtrSafe Function WinMsgBox Lib "user32" Alias "MessageBoxTimeoutA" (ByVal hWnd As LongPtr, ByVal xDescricao As String, _
             ByVal xTitulo As String, ByVal xBotoes_Avisos As VbMsgBoxStyle, ByVal xLanguage As Long, ByVal xTimeOutMilliseconds As Long) As Long
#End If

Sub Testes()
    Dim oDoc As PartDocument: Set oDoc = ThisApplication.ActiveDocument
    If Not oDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
        ThisApplication.CommandManager.ControlDefinitions.Item("PartConvertToSheetMetalCmd").Execute2 True  'Se não estiver no template de chapa, converte
        WinMsgBox 0, "", "", vbOKOnly, 0, 1
    End If
    Dim oSMDef As SheetMetalComponentDefinition: Set oSMDef = oDoc.ComponentDefinition
End Sub

 

0 Likes
Accepted solutions (2)
307 Views
2 Replies
Replies (2)
Message 2 of 3

Michael.Navara
Advisor
Advisor
Accepted solution

Try direct change of SubType instead of command execution

Sub ConvertToSheetmetalPartTest()
    Dim sheetMetalSubType As String: sheetMetalSubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}"
    Dim oDoc As PartDocument: Set oDoc = ThisApplication.ActiveDocument
    If Not oDoc.SubType = sheetMetalSubType Then
        oDoc.SubType = sheetMetalSubType
    End If
    Dim oSMDef As SheetMetalComponentDefinition: Set oSMDef = oDoc.ComponentDefinition
End Sub
0 Likes
Message 3 of 3

WCrihfield
Mentor
Mentor
Accepted solution

Hi @gustavo.cassel.  I don't know if this will fix the problem you seem to be having, but there is another simpler way to convert the PartDocument from a regular part to a sheet metal part.  The Document.SubType property is Read/Write, so you can just set it to that sheet metal specific value to convert it to a sheet metal part.  However, that conversion might just need a couple seconds to process, so a slight delay may be necessary before issuing other commands that attempt to access its SheetMetalComponentDefinition.  Have you tried Threading.Thread.Sleep(500) (number is milliseconds for half a second)?

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes