Create Text/sketch on a face in a assembly with iLogic

Create Text/sketch on a face in a assembly with iLogic

nickolas_jaderas
Contributor Contributor
1,774 Views
5 Replies
Message 1 of 6

Create Text/sketch on a face in a assembly with iLogic

nickolas_jaderas
Contributor
Contributor

In a assembly (or part), I want to select a face, on this face I want the Partnumber as a sketh text, (with a big font)

Is there a simple solution?

 

I haven't found any examples of this, not even how to create a sketch simply by selecting a face with iLogic.

 

1711-001.jpg

 

/Nickolas

0 Likes
Accepted solutions (2)
1,775 Views
5 Replies
Replies (5)
Message 2 of 6

xiaodong_liang
Autodesk Support
Autodesk Support
Message 3 of 6

nickolas_jaderas
Contributor
Contributor

Awsome!

Changed it somehow to take a custom property and let the user select the face.

 

Is it possible to change the font size? since the part is a few meters in size, I have to use fontsize 300.

Also if its possible, add the text as a text-box, that way no text-point is visible.

 

 

SyntaxEditor Code Snippet

oAssDoc = ThisApplication.ActiveDocument        

oAssDef = oAssDoc.ComponentDefinition
itemNo = iProperties.Value("Custom", "ItemNo")
Dim oFace As Face
oFace = ThisApplication.CommandManager.Pick (SelectionFilterEnum.kAllPlanarEntities,"Select the face") 

    'make sure it is a planar face
    If oFace.SurfaceType = SurfaceTypeEnum.kPlaneSurface Then
        
        oPlanarSurface = oFace.Geometry
        
            'add a sketch
        oSketch = oAssDef.Sketches.Add(oFace)    
            
        'trying to choose an appropriate point
        'assume this planar face has one edge loop only
        oEdgeLoop = oFace.EdgeLoops(1)
            
        oMinPt = oEdgeLoop.RangeBox.MinPoint 
        oMaxPt = oEdgeLoop.RangeBox.MaxPoint
            
        CenterPt = ThisApplication.TransientGeometry.CreatePoint((oMaxPt.X + oMinPt.X) / 2#, (oMaxPt.Y + oMinPt.Y) / 2#, (oMaxPt.Z + oMinPt.Z) / 2#)    
            
        'get one point on the face and transform to the point2d on the sketch 
        'Set oTextPt = oSketch.ModelToSketchSpace(oPlanarSurface.RootPoint)
        oTextPt = oSketch.ModelToSketchSpace(CenterPt)
            
            'add the textbox
        'oSketchText = oSketch.TextBoxes.AddFitted(oTextPt, "MY TEST") 
        oSketchText = oSketch.TextBoxes.AddFitted(oTextPt, itemNo) 
        
    Else
        MsgBox( "please select a planar face!")
    End If

 

0 Likes
Message 4 of 6

xiaodong_liang
Autodesk Support
Autodesk Support
Accepted solution
the easiest way is to specify the font size like below:

'double size
oSketchText.Style.FontSize = oSketchText.Style.FontSize * 2

you could also define a TextStyle with the parameters you need, and set it to
oSketchText.Style = oMyTextStyle

or set FormattedText which is an XML format that specifies text.

you may have to take a look at API help for more details.
Message 5 of 6

nickolas_jaderas
Contributor
Contributor

Thanks!
Byt I dont understand where I put in the "size"-code, I get it to work with:

 

SyntaxEditor Code Snippet

        oSketchText = oSketch.TextBoxes.AddFitted(oTextPt, itemNo)
        oSketchText.Style.FontSize = 30        

 

But not the other way around.

 

SyntaxEditor Code Snippet

        oSketchText.Style.FontSize = 30
        oSketchText = oSketch.TextBoxes.AddFitted(oTextPt, itemNo)

 

/Nickolas

0 Likes
Message 6 of 6

nickolas_jaderas
Contributor
Contributor
Accepted solution

Got it to work with:

SyntaxEditor Code Snippet

oSketchText = oSketch.TextBoxes.AddFitted(oTextPt, "<StyleOverride FontSize='30'>" & itemNo & "</StyleOverride>")

 so now it works perfectly!

 

And I learned to use the API help 🙂

 

Many thanks!

 

0 Likes