Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating annotations in CATIA V5 parallel to screen via script

Status
Not open for further replies.

RumSam

Automotive
Sep 20, 2018
1
GB
Hi All,

I am currently trying to create annotations in CATIA V5 via a script - I have managed to do normal annotations see script below however I am trying to get the annotation which is created to be parallel to screen?

There is a button in the FTA toolbar which does this - however I need it in script.

Anyone got any ideas?

(I've tried to record a macro however it doesn't pick up annotation settings/properties)

Thanks

Capture_3_upjlzx.jpg


Script so far:

set opart=GetPartFromObject(oParam1)

Set part1 = opart

Set annotationSets1 = part1.AnnotationSets

Set annotationSet1 = annotationSets1.Add("ISO_3D")

Set userSurfaces1 = part1.UserSurfaces

Set userSurface1 = userSurfaces1.Generate(oPoint)
'Above is the point

Set viewFactory1 = annotationSet1.TPSViewFactory
Set view1 =viewFactory1.CreateView(oPlane,1)

Set annotationFactory1 = annotationSet1.AnnotationFactory

Set annotation1 = annotationFactory1.CreateEvoluateText(userSurface1,50, 50, 50, True)
annotation1.text.Get2dAnnot.ActivateFrame catRectangle
annotation1.text.Get2dAnnot.FrameType = catRectangle
annotation1.Text.Get2dAnnot.SetFontName 0, 0, "Arial (TrueType)"
annotation1.Text.Get2dAnnot.SetFontSize 0, 0, CDbl("5.0")
annotation1.TransfertToView view1

oList.valuelist.Add annotation1.Text

Dim LResult1 As Long
LResult1 = Len (oParam1.Name) +4

annotation1.Text.Text = oParam1.Name & " = "
annotation1.Text.Get2dAnnot.InsertVariable LResult1 , 0, oParam1

annotation1.ModifyVisu

annotation1.Name = oParam1.Name

Set annotationSet1 = annotationSets1.Item("Annotation Set.1")
Part1.Update


End Sub
 
Replies continue below

Recommended for you

Hi RumSam!

I had the same exact problem. Finally, I managed to write annotations parallel to screen via macros by using CATIA StartCommand and the proper command, "Text Parallel To Screen". Then I used SendKeys function, but with a workaround to avoid the error message regarding lack of permissions and making the CPU wait some milisecs just to give CATIA time to process the sent keys. It's all a bit tricky but it worked for me. I copy the code below.

Hope it is helpfull to you, regards!

'-- CODE!-----------------------------------------------------------------------------
Sub AddAnnnotationsWithKeys(iHB As HybridBody, iHSIndex As Long, iText As String)

'-- Where iHSIndex is the index of the Hybrid shape which the annotation will be attached to and iHB is the Part Hybrid body where it is.---------------
Dim partDocument1 As PartDocument
Dim part1 As Part

Dim selection1 As Selection
Dim skObject As Object
'-- skObject is created only to use SendKeys function without any failure-------------

Dim newAnnot As Annotation
Dim annotationSet1 As AnnotationSet

Dim timeNoF
Dim lTimeIni As Date

Set partDocument1 = CATIA.ActiveDocument
Set part1 = partDocument1.Part

'-- Target surface is selected and then the annotation command is called---------------
Set selection1 = partDocument1.Selection
selection1.Clear
selection1.Add iHB.HybridShapes.Item(iHSIndex)
CATIA.StartCommand "Text Parallel To Screen"
CATIA.RefreshDisplay = True

'-- A generic text is sent just to create the annotation-------------------------------
Set skObject = CreateObject("wscript.shell")
skObject.SendKeys "text", True

'-- It is necesary to wait around 100 or 200 msecs to give CATIA enough time before "pressing" ENTER-----------
'-- If condition was added just for safety, in order to avoid infinite loops-----------------------------------
lTimeIni = Now
timeNoF = Timer
Do
DoEvents
If Now > (lTimeIni + "00:00:05") Then
Exit Sub
End If
Loop Until Timer > timeNoF + 0.2

skObject.SendKeys "{ENTER}", True

CATIA.RefreshDisplay = True
selection1.Clear
part1.Update

'-- Annotation parameters are finally set as desired.---------------------------------
Set annotationSet1 = part1.AnnotationSets.Item(1)
Set newAnnot = annotationSet1.Annotations.Item(annotationSet1.Annotations.Count)

newAnnot.text.text = iText
newAnnot.text.Get2dAnnot.SetFontSize 0, 0, 2.7
newAnnot.ModifyVisu

'-- ;););););););););););););););)

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top