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: 

iLogic to "Find Sketch in Browser"

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
RoyWickrama_RWEI
1413 Views, 8 Replies

iLogic to "Find Sketch in Browser"

I know the sketch name (but don't know what it is in the window). Although, I renamed in order the browser, browsing through the sketch browser to locate a sketch is still a little bit harder.

 

In order to edit the sketch (sketch name is known), I would like to seek help with an ilogic code that will show in the sketch in the sketch browser.

I thank for all replies.

8 REPLIES 8
Message 2 of 9

Hey, you can use this:

 

Dim oDoc As Document = ThisApplication.ActiveDocument
Dim oCD As ComponentDefinition = oDoc.ComponentDefinition
Dim oSketch As Sketch = oCD.Sketches.Item("MySketchName")
If oSketch Is Nothing Then Exit Sub oSketch.Edit() Try 'Do something with the sketch Catch
End Try oSketch.ExitEdit()

 

Or if you really just want to select it:

 

Dim oDoc As Document = ThisApplication.ActiveDocument
Dim oCD As ComponentDefinition = oDoc.ComponentDefinition
Dim oSketch As Sketch = oCD.Sketches.Item("MySketchName")
If oSketch Is Nothing Then Exit Sub
oDoc.SelectSet.Select(oSketch)
Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
Message 3 of 9

Thanks a lot in replying to my request. It is so great. Mostly, I like the 2nd option. My iLogic is productive with your help.

 

Message 4 of 9

Thanks a lot in replying to my request. It is so great. Mostly, I like the 2nd option. My iLogic is productive with your help.

Capture.GIF

 

 

 

 

 

 

 

 

 

 

 

I incorporated a lot of iLogic in my ideal iLogic rich project (but more to go). Thank you.

 

Message 5 of 9

You're welcomed.

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
Message 6 of 9

I further revised the code a little bit (because it was giving an error message in case I input invalid data) so that it runs better.

Dim oDoc As Document = ThisApplication.ActiveDocument
Dim oCD As ComponentDefinition = oDoc.ComponentDefinition
Dim oSketch As Sketch
Dim oFindSketch As String

100:
oFindSketch = "SK-00000, example. Type sketch name." 
oFindSketch = InputBox("Prompt", "Title", oFindSketch, MessageBoxButtons.YesNoCancel)

For Each oSketch In oDoc.ComponentDefinition.Sketches
		If Not oFindSketch = oSketch.Name Then 
		Counter = 0
		Else
		Counter = 1
		oSketch = oCD.Sketches.Item(oFindSketch)
		Exit For
		End If
Next
	
If Counter = 0 Then			'Not OK
	oInfo = MessageBox.Show("The sketch name typed in is " & "NOT VALID." _
	& vbLf & "Do you want to retry?", "Title", MessageBoxButtons.YesNo)
	If oInfo = vbYes Then
		Goto 100:
	Else If oInfo = vbNo Then
	'Do noting
	End If
Else If Counter = 1 Then	'OK
	oDoc.SelectSet.Select(oSketch)
End If

Message 7 of 9

Sometimes it is unclear that there is some object selected

Reasons may be 

Object is not visible in browser (sketch hidden inside feature)

Or there are too many objects (object list is longer than vertical app window size can fit)

 

What else could be done to set focus exactly on the selected browser object  ?

Message 8 of 9

You are right. Thanks a lot.

Please try with the attached rule.

Note: I got help from one of the postings by Curtise Weguespack (see the link below).

My profuse thanks go to Curtise as well.

 

Ref: https://forums.autodesk.com/t5/inventor-customization/ilogic-underconstrained-sketches/td-p/3104766

 

 

Message 9 of 9

Thank you it helped a bit for single object selection.

In fact I'm writing app that selects several objects (features) of the part.

In some cases (Derived IAM) features are hidden two levels deep.

I've added oControlDef.Execute after selecting each feature but it does not open second level for all but first feature. Seems like I need to learn more regarding browsers...

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

Post to forums  

Autodesk Design & Make Report