Change Circular Pattern Quantity in sketch symbol

Change Circular Pattern Quantity in sketch symbol

snichols
Advocate Advocate
371 Views
1 Reply
Message 1 of 2

Change Circular Pattern Quantity in sketch symbol

snichols
Advocate
Advocate

Working on some drawing automation and I have the need to change the quantity of a circular pattern in a sketched symbol. I tried the below code with the parameters set in the drawing and it worked for all the dimensions but not the pattern qty.

 

Option Infer On
Option Explicit On

Dim odoc As DrawingDocument
Dim osymb As SketchedSymbolDefinition
Dim osheet As Sheet
Dim oparam As Parameter
Dim UnderscorePos As Integer
Dim Paramname As String
Dim Dimensionname As String
Dim otitle As TitleBlockDefinition

odoc = ThisDoc.Document

ThisApplication.ScreenUpdating = False

Try

For Each oparam In odoc.Parameters
    'Find the position of the underscore to get the parameter name and the name of the corresponding dimension
    UnderscorePos = InStr(oparam.Name, "_")
    'if no underscore go to next parameter
    If UnderscorePos = 0 Then
        Continue For
    End If
    
    Paramname = Left(oparam.Name, UnderscorePos - 1)
    Dimensionname = Right(oparam.Name, Len(oparam.Name) - UnderscorePos)
        
    For Each osymb In odoc.SketchedSymbolDefinitions
        Dim oSketch As DrawingSketch
        If Paramname = osymb.Name Then
            Call osymb.Edit(oSketch)
            For Each constraintX In oSketch.DimensionConstraints
                Dim paramX = constraintX.Parameter
                If (paramX.Name = Dimensionname) Then
                    paramX._Value = oparam._Value ' Update the dimension in the sketched symbol with the parameter value
                End If
            Next
            osymb.ExitEdit (True)
            
            'reedit the symbol or title to ensure the change did not corrupt the sketch
            Call osymb.Edit(oSketch)
            osymb.ExitEdit (True)
            
        End If
    Next osymb
    
    For Each otitle In odoc.TitleBlockDefinitions
        Dim oSketch As DrawingSketch
        If Paramname = otitle.Name Then
            Call otitle.Edit(oSketch)
            For Each constraintX In oSketch.DimensionConstraints
                Dim paramX = constraintX.Parameter
                If (paramX.Name = Dimensionname) Then
                    paramX._Value = oparam._Value ' Update the dimension in the sketched symbol with the parameter value
                End If
            Next
            otitle.ExitEdit (True)
            
            'reedit the symbol or title to ensure the change did not corrupt the sketch
            Call otitle.Edit(oSketch) 
            otitle.ExitEdit (True)
             
        End If
    Next otitle
    
Next oparam

Catch 
    'in case of error when editing one of the sketch
    Call ThisApplication.TransactionManager.UndoTransaction
    Call ThisApplication.TransactionManager.UndoTransaction
    ThisApplication.ScreenUpdating = True
    MsgBox (Paramname & " could not be changed")
    
Finally
    ThisApplication.ScreenUpdating = True
    ThisApplication.ActiveView.Update()

End Try

 

So I tried doing it with the command manager with the below code. It works somewhat but seems temper-mental.

 

Imports System.Windows.Forms
    ' Get the CommandManager object.
    Dim oCommandMgr As CommandManager
    oCommandMgr = ThisApplication.CommandManager

    ' Get control definition for the line command.
    Dim oControlDef As ControlDefinition
    oControlDef = oCommandMgr.ControlDefinitions.Item("SketchPatternEditCtxWrapperCmd") 
    ' Execute the command.'    Call oControlDef.Execute

    Call oControlDef.Execute2(False)
    
'    opens To Custom tab ( send "right arrow" key 4 times)
    SendKeys.Sendwait("{TAB 2}")
    SendKeys.Sendwait("{9}")
'    SendKeys.Sendwait("{6}")'    ThisApplication.UserInterfaceManager.DoEvents()'    SendKeys.Sendwait("{TAB 4}")
oControlDef = oCommandMgr.ControlDefinitions.Item("AppContextual_OKCmd")
Call oControlDef.Execute

 

This is what the sketch symbol looks like, just a pattern of the circles:

snichols_0-1591637324201.png

 Has anybody found a way to update the pattern qty in a sketch symbol?

Thanks in advance for any help.

0 Likes
372 Views
1 Reply
Reply (1)
Message 2 of 2

snichols
Advocate
Advocate

snichols_0-1591637838520.png

These are the parameters for the first batch of code, sorry I forgot them in the original post.

0 Likes