Component name linked the sketch text

Component name linked the sketch text

tookemtoni
Collaborator Collaborator
335 Views
3 Replies
Message 1 of 4

Component name linked the sketch text

tookemtoni
Collaborator
Collaborator

Hi, We are moving from Fusion 360 to Inventor and this script is very important to our workflow. How can you do this in Inventor? See attached link the solved post in Fusion 360 forum. 

https://forums.autodesk.com/t5/fusion-360-api-and-scripts/component-name-linked-sketch-text/m-p/1015...

0 Likes
336 Views
3 Replies
Replies (3)
Message 2 of 4

theo.bot
Collaborator
Collaborator

You can follow the same way as brian showed in his fusion sample. You can check if a particular sketch is in your part and edit the text box that is in that sketch. But when you start writing your code you need to think when you are going to run your code. On part level or on assembly level? Inventor has a slightly different structure as it comes to parts and assemblies. 

 

here is a small sample rule that you can run on part level.

 

 Sub main
	 Dim oDoc As PartDocument
oDoc = ThisDoc.Document 
 
 Dim oCompdef As PartComponentDefinition
 oCompdef = oDoc.ComponentDefinition
 
 Dim sk As PlanarSketch
 'try to get the sketch "CompName"
 Try
 sk = oCompdef.Sketches.Item("CompName")
  Catch
	 Logger.Info("no sketch found.")
 Exit Sub
 End Try
 
 'assuming that the sketch contains a textbox and that the file is saved.
 sk.TextBoxes.Item(1).Text = IO.Path.GetFileNameWithoutExtension(oDoc.FullFileName)
 
End Sub

  

Message 3 of 4

tookemtoni
Collaborator
Collaborator
Great news. We would run this code at assembly level.
0 Likes
Message 4 of 4

theo.bot
Collaborator
Collaborator

You create a rule, that loops thru your components as you can read here: Mod the Machine: Accessing Assembly Components (typepad.com).
In that loop you can create the steps like I've shown in the first reply.