Hello everyone, I'm having trouble getting textboxes created by AddFitted or AddByRectangle to work with the movesketchobjects and RotateSketchObjects methods.
I have code that I wrote that moves textboxes in an assembly based on the origin of a textbox and the rotation of a textbox in API and moves the textboxes to a location above a component.
The code worked just fine with the User Interface created textboxes, but not the API created textboxes. The Idea is that someone could delete one of the textboxes and then the illogic would look through each of the sketches, check the formatted text of each of the textboxes, create the textboxes that are missing, and capture the textbox indices for moving the textbox later in the code... And I can confirm that it does that.
The Problem is that even though inventor knows where the textbox is, and can spit out what text is in the textbox and display it in a message box. Despite not missing any of the necessary parameters the move sketch objects method doesn't move it...
Changing the API textboxes "Rotation" Property does work, but only allows me to turn it 90 degrees, compared to the Rotate Sketch Objects method that would allow me to rotate it any amount that I need to. (I'm using a wingdings 3 Arrow)
Anyway I was thinking if I could somehow use the user command "sketch text" or " ThisApplication.CommandManager.ControlDefinitions.Item("AppTextWrapperCmd")" through Ilogic I might be able to get around my problem...
However I don't know how to convince Inventor that I left clicked inside the Sketch.
Does anyone know how to do this? Either Simulating left clicking in inventor or a work around for moving API textboxes?
If you do, that would be a lot of help.
Thank you!
(Sorry, it's my first post.)
here is the code, It is in ILogic.
If SingleArrowTextSwitch = 0 SingleArrowPlanarSketch = ThisDoc.Document.ComponentDefinition.Sketches.Add(ElevationPlaneObject) oTextBox112 = SingleArrowPlanarSketch.TextBoxes.AddByRectangle( TranGeo.CreatePoint2d(3, 18), TranGeo.CreatePoint2d(150, 60), teststring ) SingleArrowPlanarSketch.Edit() SingleArrowPlanarSketch.ExitEdit() Else MessageBox.Show("Spotted 4", "Title") End If Dim XtextboxOri1 As Double Dim YtextboxOri1 As Double Dim TestVector01 As Vector2d TextBoxLocationX=ThisDoc.Document.ComponentDefinition.Sketches.Item(SingleArrowSketchIndex).TextBoxes.Item(SingleArrowTextBoxIndex).Origin().X MessageBox.Show("Message7", "Title") TextBoxLocationY=ThisDoc.Document.ComponentDefinition.Sketches.Item(SingleArrowSketchIndex).TextBoxes.Item(SingleArrowTextBoxIndex).Origin().Y XtextboxOri1 = ThisDoc.Document.ComponentDefinition.Sketches.Item(SingleArrowSketchIndex).TextBoxes.Item(SingleArrowTextBoxIndex).Origin().X YtextboxOri1 = ThisDoc.Document.ComponentDefinition.Sketches.Item(SingleArrowSketchIndex).TextBoxes.Item(SingleArrowTextBoxIndex).Origin().Y XtextboxOri1=XtextboxOri1*(-1) YtextboxOri1=YtextboxOri1*(-1) 'Dim TestVector2 As Vector2d MessageBox.Show(CStr(ThisDoc.Document.ComponentDefinition.Sketches.Item(SingleArrowSketchIndex).TextBoxes.Item(SingleArrowTextBoxIndex).Origin().Y),"Y of Origin") MessageBox.Show(CStr(ThisDoc.Document.ComponentDefinition.Sketches.Item(SingleArrowSketchIndex).TextBoxes.Item(SingleArrowTextBoxIndex).Origin().X),"X of Origin") Dim TextBoxCollection1 As ObjectCollection 'Reserves Name TextBoxCollection1=ThisApplication.TransientObjects.CreateObjectCollection 'Reserves Data (It's required for the ObjectCollection object) Dim oTextboxobject1 As Object oTextboxobject1 = ThisDoc.Document.ComponentDefinition.Sketches.Item(SingleArrowSketchIndex).TextBoxes.Item(1) TextBoxCollection1.Add(oTextboxobject1) MessageBox.Show("Message8", "Title") MessageBox.Show(oTextboxobject1.Text, "Title") Dim TextRotate2 As Double TextRotate2=1 Dim TextRotate1 As Double Dim Rotatepoint1 As Point2d TextRotate1= ThisDoc.Document.ComponentDefinition.Sketches.Item(SingleArrowSketchIndex).TextBoxes.Item(SingleArrowTextBoxIndex).Rotation() Rotatepoint1=ThisDoc.Document.ComponentDefinition.Sketches.Item(SingleArrowSketchIndex).TextBoxes.Item(SingleArrowTextBoxIndex).Origin() While TextRotate2>0 TextRotate1= ThisDoc.Document.ComponentDefinition.Sketches.Item(SingleArrowSketchIndex).TextBoxes.Item(SingleArrowTextBoxIndex).Rotation() MessageBox.Show("Text Rotate 1", CStr(TextRotate1)) MessageBox.Show("Text Rotate 2", CStr(TextRotate2)) TextrotateInfo2=ThisDoc.Document.ComponentDefinition.Sketches.Item(SingleArrowSketchIndex).TextBoxes.Item(SingleArrowTextBoxIndex).Rotation() Dim Coordsholder1(2) As Double Coordsholder1(2)=Sin(TextRotate1) Coordsholder1(1)=Cos(TextRotate1) Dim Unitvectortext1 As UnitVector2d Unitvectortext1=ThisApplication.TransientGeometry.CreateUnitVector2d( Coordsholder1(1), Coordsholder1(2) ) TextRotate2 =Unitvectortext1.AngleTo(ComponentDirectionlVector.AsUnitVector) MessageBox.Show("Text Rotate 2 Check", CStr(TextRotate2)) TextrotateInfo=TextRotate2 ThisDoc.Document.ComponentDefinition.Sketches.Item(SingleArrowSketchIndex).RotateSketchObjects(TextBoxCollection1, Rotatepoint1, TextRotate2) ThisDoc.Document.ComponentDefinition.Sketches.Item(SingleArrowSketchIndex).RotateSketchObjects(TextBoxCollection1, Rotatepoint1, Pie/2) End While TestVector01 = ThisApplication.TransientGeometry.CreateVector2d(XtextboxOri1+Xdist*2.54+16.75*Cos(TextRotate1+(PI/2))*2.54, YtextboxOri1+yDist*2.54+16.75*Sin(TextRotate1+(PI/2))*2.54) ThisDoc.Document.ComponentDefinition.Sketches.Item(SingleArrowSketchIndex).MoveSketchObjects(TextBoxCollection1, TestVector01)