Continue to Site

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!

CREATE POINTS ON CURVE 1

Status
Not open for further replies.

JeniaL

Mechanical
Jun 3, 2014
547
IL
recording macro for creating points doesn't work for me, moreover marco records entities names. not good for me.
can anybody share sample macro for creating points on curve? needed for composites (laser projection)

thanks in advance.
 
Replies continue below

Recommended for you

how can i control number of digits after point? need to output just one digit.
catscript

ostream.Write ("GOTO X" & Chr(0032) & acoord(0) & Chr(0009) & "Y" & Chr(0032) & acoord(1) & Chr(0009) & "Z" & Chr(0032) & acoord(2) & Chr(10))
 
try [...]& Format(acoord(0), "#.##")& [...]

Eric N.
indocti discant et ament meminisse periti
 
ostream.Write ("GOTO X" & Chr(0032) & Format(acoord(0), "#.##") & Chr(0009) & "Y" & Chr(0032) & Format(acoord(1), "#.##") & Chr(0009) & "Z" & Chr(0032) & Format(acoord(2), "#.##") & Chr(10))

Eric N.
indocti discant et ament meminisse periti
 
looks like CATScript does not like vba Format()...

solution: like in the old time... b=int(a*10)/10

[...]& Chr(0032) & int((acoord(0)*10)/10 & Chr(0009) & "Y" [...]

This will not force the 0 digit if any.

Eric N.
indocti discant et ament meminisse periti
 
to force the .0 digit you need to create it:


dim formatednumber(2)


for u=0 to 2
formatednumber(u) = int (acoord(u)*10)/10
if int(acoord(u)*10)/10 - int(acoord(u))=0 then
formatednumber(u) =int (acoord(u)) & ".0"
end if
next

ostream.Write ("PENDOWN" & Chr(10))
ostream.Write ("GOTO X" & Chr(0032) & formatednumber(0) & Chr(0009) & "Y" & Chr(0032) & formatednumber(1) & Chr(0009) & "Z" & Chr(0032) & formatednumber(2) & Chr(10))
ostream.Write ("PENUP"& Chr(10))
Next


Eric N.
indocti discant et ament meminisse periti
 
thanks a lot. now it works. btw how can i loop geometrical set selection?..i want to select as much as i have geometrical sets with points and in the end create txt file
 
To GS points save in a txt is something like this.

Code:
Sub CATMain()
Dim oPartDoc As Part
On Error Resume Next
Set oPartDoc = CATIA.ActiveDocument.Part 
If Err.Number <> 0 Then                 
Message = MsgBox("Sorry, This script works with a CATPart as Active document", vbCritical, "Error")
Exit Sub
End If

' What do you want to select
Dim EnableSelectionFor(0)
  EnableSelectionFor(0) = "HybridBody"
' Reset the Selection
Set sSEL = CATIA.ActiveDocument.Selection
  sSEL.Clear
' Define Selection
  MsgBox "Please Select the Geometrical Set where you have the points"
  UserSelection = sSEL.SelectElement2(EnableSelectionFor, "Please select another Geometrical Set", False)
' Evaluation if the selection is correct or not
If UserSelection <> "Normal" Then
      MsgBox "Error with the selection"
    Exit Sub
Else
Set ohybridbody = sSEL.Item(1).Value
End If
Set partDocument1 = CATIA.ActiveDocument
Dim selection1 As Selection
Set selection1 = partDocument1.Selection
selection1.Search "CATPrtSearch.Point,sel"
REM Set visPropertySet1 = selection1.visProperties
REM VisPropertySet1.SetShow 1
'''''''''''''''''''''''''''''''
Dim part1 As Parts
Set part1 = partDocument1.Part
Dim selection As Selection
Set selection = Catia.ActiveDocument.Selection
Dim hybridShapeFactory1 As HybridShapeFactory
Set hybridShapeFactory1 = part1.HybridShapeFactory
Dim Obj As VispProperties
Set Obj = Selection.VisProperties
Set visProperties1 = CATIA.ActiveDocument.Selection.VisProperties
visProperties1.SetLayer catVisLayerNone, None
REM selection1.Clear
Part1.Update
Dim specsAndGeomWindow1 As Window
Set specsAndGeomWindow1 = CATIA.ActiveWindow
Dim viewer3D1 As Viewer
Set viewer3D1 = specsAndGeomWindow1.ActiveViewer
Dim viewpoint3D1 As Viewpoint3D
Set viewpoint3D1 = viewer3D1.Viewpoint3D
viewer3D1.Reframe
Set viewpoint3D1 = viewer3D1.Viewpoint3D
Set body1 = Bodies1.Item("PartBody")                     
Part1.InWorkObject = Body1
'run another catscript
Dim EmptyPar()
Dim ScPath
ScPath = "C:\temp\"
CATIA.SystemService.ExecuteScript scpath, catScriptLibraryTypeDirectory, "LineNormalToSurface.CATScript", "CATMain", EmptyPar
End Sub

This code is not mine. I found thanks to ferdo.

greetings.
Urim
 
still got no success with points creation. to record a macro doesn't work for me. i need to create points on curve with end points option on. any ideas guys?
 
It sounds like you want to use the feature "Points and planes repetition"...the only thing I found on this is
CATIA.StartCommand "Points And planes Repetition"
But this will only launch the command, the user will need to fill out the form and hit ok. Also, I am not sure how you could select multiple curves and run Points and planes repetition and have the macro "wait" for you to ok the points and planes repetition window...there may be a way though.

You may be able to have a macro that behaves differently based on what the user selects. If they pick a curve, it launches points and planes repetition...if they pick a part, it writes out the text file. If you have 10s or 100s of curves to select...this would not be a good option.

The more difficult (but maybe more efficient if you have a lot of curves) approach would be to create the points manually in your macro (don't use points and planes repetition)
The user selects several curves then inputs the number of points they want on the curves
The macro calculates: Ratio = 1/(# of instances - 1) then loops to create the points

For i=1 to oSelection.Count 'many curves are selected
For i = 0 to # of instances​
'Create a point at i*Ratio​
Next​
Next

You also mentioned looping through geosets...do the curves already exist in the geosets? Are the points supposed to go in the same geoset as the curve?

It is difficult to help without knowing exactly what you need to do.
 
well it's more complicated.
why do i need that? laser projection for composite parts.
so i have several closed contours located in the same geometrical set.
macro have to disassemble contour, create points with specified distance including end points. created points for each contour must be in a separate geo set. at this step i'm not talking about export to txt all that points. this will be next step.

i have an exe program but it works slow especially on big parts.
i guess the reason it works slow is ratio. in exe i have points also created using ratio and not points and planes repetition.
seems like points and planes repetition works faster.
see how looks spec tree

download.aspx
 
with a following macro can't figure out how to export points from several geo sets. after exporting points from first geo set i need penup command and then coordinates from second geo set and so on.
guys really need help on that.
thanks in advance.

Code:
'num = 1 ' num of NumDigAfterDec
'Language = "VBSCRIPT"

Sub CATMain()

Dim filename As String
filename = CATIA.ActiveDocument.Name
Dim path As String
path = CATIA.ActiveDocument.path
Dim partDoc As PartDocument
Set partDoc = CATIA.ActiveDocument

Dim oPartDoc As Part
On Error Resume Next
Set oPartDoc = CATIA.ActiveDocument.Part
If Err.Number <> 0 Then
Message = MsgBox("Sorry, This script works with a CATPart as Active document", vbCritical, "Error")
Exit Sub
End If

' What do want to select

Dim EnableSelectionFor(0)
EnableSelectionFor(0) = "HybridBody"

' Reset the Selection

Set sSel = CATIA.ActiveDocument.Selection
sSel.Clear

' Define Selection

MsgBox "Please Select the Geometrical Set where are the points for extracting"

UserSelection = sSel.SelectElement3(EnableSelectionFor, "Please select another Geometrical Set", False, CATMultiSelTriggWhenUserValidatesSelection, True)
' Evaluation if the selectio is correct or not
If UserSelection <> "Normal" Then
MsgBox "Error with the selection"
Exit Sub
Else
Set ohybridbody = sSel.Item(1).Value

MsgBox "The Geometrical Set selected is : " & ohybridbody.Name

End If


ReDim acoord(2)
'--------------------------------------------------------------------------------
' The location of the result file
'--------------------------------------------------------------------------------
'Dim filename As String

'filename = CATIA.FileSelectionBox("Where do you want to save the result file", "*.txt", CatFileSelectionModeSave)

Set Datos = CATIA.FileSystem.CreateFile(path & "\" & CATIA.ActiveDocument.Name & ".txt", True)

Set ostream = Datos.OpenAsTextStream("ForAppending")

ostream.Write (oPartDoc.Name & Chr(10))
ostream.Write (" " & Chr(10))
'ostream.Write ("The selected Geometrical Set was : " & ohybridbody.Name & Chr(10))
ostream.Write (" " & Chr(10))
ostream.Write ("$* PLY" & Chr(32) & ohybridbody.Name & Chr(10))
ostream.Write ("PENDOWN" & Chr(10))

Set oshapes = ohybridbody.HybridShapes

For i = 1 To oshapes.Count
oshapes.Item(i).GetCoordinates acoord

Set reference1 = oshapes.Item(i)

Dim formatednumber(2)


For U = 0 To 2
formatednumber(U) = Int(acoord(U) * 10) / 10
If Int(acoord(U) * 10) / 10 - Int(acoord(U)) = 0 Then
formatednumber(U) = Int(acoord(U)) & ".0"
End If
Next

'ostream.Write ("PENDOWN" & Chr(10))
ostream.Write ("GOTO " & Chr(32) & formatednumber(0) & Chr(32) & "" & Chr(32) & formatednumber(1) & Chr(32) & "" & Chr(32) & formatednumber(2) & Chr(10))
'ostream.Write ("PENUP" & Chr(10))
'ostream.Write ("GOTO " & Chr(32) & formatednumber(0) & Chr(32) & "" & Chr(32) & formatednumber(1) & Chr(32) & "" & Chr(32) & formatednumber(2) & Chr(10))
Next



ostream.Write ("PENUP" & Chr(10))
ostream.Close

'MsgBox "Points Exported :" & (i-1) & " POINTS" & Chr(10) & Chr(10) & "Please Check the following file for result : " & chr(10) & chr(10) & filename & chr(10)& chr(10) & "Process finished"
MsgBox "Check results in folder " & Chr(10) & path & "\" & Chr(10) & Chr(10) & "File:" & Chr(10) & partDoc.Name & ".txt" & Chr(10)
End Sub
 
do you want the next geomSet to be selected by user like the first one or maybe you have a logical naming convention that would help your script to find it?

Eric N.
indocti discant et ament meminisse periti
 
i want to select several geo sets at once. thats why i use selectElement3 and then export all the selections. however each set must be started with penup pendwn commands. here's the example. with macro i posted above i can only export one geo set
just need i hint how to do that.
download.aspx
 
you define the geomSet with the line:

Set ohybridbody = sSel.Item(1).Value

you could replace that by

Set ohybridbody = sSel.Item(u).Value

and include all required lines into a for u = 1 to sSel.count // next loop

Eric N.
indocti discant et ament meminisse periti
 
if i change 1 to u nothing happens and moreover u already used in the macro so i get an error.
 
and include all required lines into a for u = 1 to sSel.count // next loop

Eric N.
indocti discant et ament meminisse periti
 
i'm definitely doing something wrong. now my txt file is empty. can you please point yo the lines i have to change. macro posted above.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top