Message 1 of 6
How to programmatically cancel a ControlDefinition?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I can't figure out how to execute a control definition more than once without user interaction. The example code below only works when I press the escape key multiple times.
I'm using control definitions to add constraints, because I couldn't get SketchBlockDefinition.GeometricConstraints to work.
I'm using Inventor 2020 - Build 168
'This iLogic code adds horizontal and vertical constraints to the selected lines.
Option Explicit On
Imports System.Linq
Dim app As Inventor.Application = ThisApplication Dim doc As Document = ThisDoc.Document Dim selSet As SelectSet = doc.SelectSet Dim cmdMgr As CommandManager = app.CommandManager Dim ctrlDefs As ControlDefinitions = cmdMgr.ControlDefinitions Dim i As Integer = 0 For Each oSketchLine In selSet.OfType(Of SketchLine).ToList selSet.Clear selSet.Select(oSketchLine) If i Mod 2 = 0 Then ctrlDefs("SketchHorizontalConstraintCmd").Execute2(True) Else ctrlDefs("SketchVerticalConstraintCmd").Execute2(True) End If i+=1 Next
This example uses GeometricConstraints:
'This iLogic code is supposed to add horizontal constraints to all lines in the active sketch, 'sketch block, or sketch block definition. It only works in a sketch. Option Explicit On Dim app As Inventor.Application = ThisApplication Dim doc As Document = ThisDoc.Document Dim selSet As SelectSet = doc.SelectSet Dim cmdMgr As CommandManager = app.CommandManager Dim ctrlDefs As ControlDefinitions = cmdMgr.ControlDefinitions Dim activatedObject As Object = doc.ActivatedObject Dim oSketchLines As SketchLines Dim gc As GeometricConstraints If activatedObject.Type = kSketchBlockObject Then Dim def As SketchBlockDefinition = activatedObject.Definition gc = def.GeometricConstraints oSketchLines =def.SketchLines Else gc = activatedObject.GeometricConstraints oSketchLines = activatedObject.SketchLines End If For Each tmpLine As SketchLine In oSketchLines gc.AddHorizontal(tmpLine) Next