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: 

Drawing file - how to identify a TextBox with unique Id or by name

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
planglais75
1086 Views, 7 Replies

Drawing file - how to identify a TextBox with unique Id or by name

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

7 REPLIES 7
Message 2 of 8
ChrisAtherton
in reply to: planglais75

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.

Chris Atherton
IEng MIMechE BEng Hons
Design Automation Services Manager | Symetri
https://uk.linkedin.com/in/chrissoathe
Message 3 of 8
jdkriek
in reply to: ChrisAtherton

Attributes are lovely aren't they? 😉

Jonathan D. Kriek
MFG Solutions Engineer
KETIV Technologies, Inc.


Message 4 of 8
planglais75
in reply to: ChrisAtherton

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

Message 5 of 8

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.

Message 6 of 8

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:

Result.jpg

 

Thanks, 

Pascal Langlais

Message 7 of 8
adam.nagy
in reply to: planglais75

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,



Adam Nagy
Autodesk Platform Services
Message 8 of 8
planglais75
in reply to: adam.nagy

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

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

Post to forums  

Autodesk Design & Make Report