Hi all,
The TextBoxes don't have a Name property or an UniqueIdentifier property. So, I don't know how to find a specified TextBox.
I've tried to add a XML comment by code in the FormattedText property and got an error.
Anyone know a solution?
Thanks,
Pascal
Solved! Go to Solution.
Solved by adam.nagy. Go to Solution.
I've added attributes to mine. These are a bit like hidden iProperties for objects in Inventor:
http://adndevblog.typepad.com/manufacturing/2013/01/inventor-set-attributes-through-api.html
By adding them you can search for attributes of a certain name or value then use them to select the associated object.
Hi Chris,
I am able to add an AttributeSet (AttributeSets.Count = 1) but, when I edit the sketch the count is 0.
What I doing wrong?
Pascal
Hi Pascal,
Which object you added the attribute? Are you sure it was Sketch? Please provide a small demo on what you are doing. It will help to know what happened.
Hi Xiaodong,
Here's a little C# demo that reproduces the problem. I tried to send you the complete solution (in a .zip file) but I get an error: "The file is corrupted. Please update a valid file". So, I attach a .txt file that represent the Program.cs file.
Before starting, you must create a new drawing with a TitleBlockDefinition that must include one text box.
The demo use the first TitleBlockDefinition in the active drawing document and showing the count of AttributeSet of the first TextBox.
Here's the result:
Thanks,
Pascal Langlais
Hi Pascal,
2 things:
1) Sketch editing of title block definition, i.e. Edit() / ExitEdit(), seems to rely on a copy of the sketch, so you would need to add the attribute set with CopyWithOwner = True
2) All sketch editing of the title block definition should be done inside an Edit() / ExitEdit() section including modifying the attributes of a text box inside the sketch
Once I followed the above the attributes remained in tact:
static void test() { Application = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application") as Inventor.Application; if (Application.ActiveDocument == null) Console.WriteLine("There is no active document in Inventor."); else if (!(Application.ActiveDocument is DrawingDocument)) Console.WriteLine("Active document should be a drawing document."); else { // Get active drawing document Document = Application.ActiveDocument as DrawingDocument; // Get ANSI large title block definition TitleBlockDefinitions titleBlockDefinitions = Document.TitleBlockDefinitions; TitleBlockDefinition titleBlockDef1 = titleBlockDefinitions[1]; // Show counts of attribute set and attribute (should be 0) TextBox textBox = titleBlockDef1.Sketch.TextBoxes[1]; Console.WriteLine("AttributeSets.Count => " + textBox.AttributeSets.Count.ToString() + " , Expected = 0 (Before creating)"); /////////////////////////////////////////////////////////////////// // Real modification, adding the Attribute set /////////////////////////////////////////////////////////////////// // Edit sketch DrawingSketch sketch; titleBlockDef1.Edit(out sketch); // Add Attribute set and attribute textBox = sketch.TextBoxes[1]; AttributeSet myAttributeSet = textBox.AttributeSets.Add("MySet", true); Inventor.Attribute myAttribute = myAttributeSet.Add("MyAttribute", ValueTypeEnum.kStringType, "MyAttributeValue"); // Exit sketch with saving titleBlockDef1.ExitEdit(true); // Show counts of attribute set and attribute (should be 1) textBox = titleBlockDef1.Sketch.TextBoxes[1]; Console.WriteLine("AttributeSets.Count => " + textBox.AttributeSets.Count.ToString() + " , Expected = 1 (After creating, before editing sketch)"); /////////////////////////////////////////////////////////////////// // Fake modification, just for testing that the Attribute remains /////////////////////////////////////////////////////////////////// //DrawingSketch sketch; titleBlockDef1.Edit(out sketch); // Exit sketch with saving titleBlockDef1.ExitEdit(true); // Show counts (ERROR USED TO BE HERE => should be 1 but previously showed 0) textBox = titleBlockDef1.Sketch.TextBoxes[1]; Console.WriteLine("AttributeSets.Count => " + textBox.AttributeSets.Count.ToString() + " , Expected = 1 (After ExitEdit)"); Console.ReadKey(); } }
Cheers,
Hi Adam,
Thanks for your explanations, it seems logical.
Leaving on holidays now but I will have a look at your solution upon my return.
Kind regards,
Pascal