CATIA V5 | 3DEXPERIENCE
Vous souhaitez réagir à ce message ? Créez un compte en quelques clics ou connectez-vous pour continuer.
Le Deal du moment : -50%
-50% Baskets Nike Air Huarache Runner
Voir le deal
69.99 €

creation de ligne

Aller en bas

R?solu creation de ligne

Message par raphael_59240 Mar 26 Mai 2015 - 16:06

bonjour,

je fais un travail répétitif qui consiste à faire des traits de 100 mm de long avec un angle donné.
je voudrais avoir le même principe que l'icone droite dans le sketch. avec L=100 et un A = 20 , 70, 110 ou 160 à partir d'un point sélectionné.

j espère avoir été clair dans mon souhait.


Merci d avance


raphael
raphael_59240
raphael_59240
actif
actif

Messages : 127
Date d'inscription : 28/03/2015
Age : 53
Localisation : dunkerque

Revenir en haut Aller en bas

R?solu Re: creation de ligne

Message par raphael_59240 Mer 27 Mai 2015 - 12:07

Bonjour,


Ben j ai chercher et j ai trouver une grosse partie
Code:
Sub CATMain()


Dim ainformations(1, 3)
Dim apointcoordinates(2)
Dim oselection As Object, opoint As Object
Dim Selection1 As Object
Dim InPutObjectType(0)
Dim oCurrentLine1   As AnyObject
Dim oPartBody As Body
Dim oPart As Part
Dim oFactory2D As Factory2D
Dim oPartDocument As Document
Dim x As Single, y As Single

Set oPartDocument = CATIA.ActiveDocument
Set oPart = oPartDocument.Part
Set oPartBody = oPart.MainBody






Set Selection1 = CATIA.ActiveDocument.Selection


InPutObjectType(0) = "Point2D"
Status = Selection1.SelectElement2(InPutObjectType, "Select a point", False)

Set opoint = Selection1.Item(1).Value

opoint.GetCoordinates apointcoordinates
ainformations(1, 0) = opoint.Name
'ainformations(1, 1) = opoint.GeometricType
ainformations(1, 2) = apointcoordinates(0)
ainformations(1, 3) = apointcoordinates(1)
x = ainformations(1, 2)
y = ainformations(1, 3)

MsgBox "Nom = " & ainformations(1, 0) & Chr(13) & Chr(13) & "X= " & ainformations(1, 2) & Chr(13) & "Y= " & ainformations(1, 3)

Set oCurrentSketch = oPartBody.Sketches.Item(opoint.Parent.Parent.Name)

Set oFactory2D = oCurrentSketch.OpenEdition

Set oCurrentLine1 = oFactory2D.CreateLine(x, y, x + 100, y + 50)
End Sub


maintenant il me faux les fixités... avez vous des idées?
raphael_59240
raphael_59240
actif
actif

Messages : 127
Date d'inscription : 28/03/2015
Age : 53
Localisation : dunkerque

Revenir en haut Aller en bas

R?solu Re: creation de ligne

Message par raphael_59240 Mer 27 Mai 2015 - 15:09

voila le code fini;)........
pour ceux que ça intéresse
Code:

--------------
Sub CATMain()

Call tracer(20)


End Sub
---------------------------------------
Sub tracer(val_angle As Single)

Dim ainformations(1, 3)
Dim apointcoordinates(2)
Dim oselection As Object, opoint As Object, oline As Object
Dim Selection1 As Object, selection2 As Object
Dim InPutObjectType(0)
Dim InPutObjectType1(0)
Dim oCurrentLine1   As AnyObject
Dim oPartBody As Body
Dim oPart As Part
Dim oFactory2D As Factory2D
Dim oPartDocument As Document
Dim x As Single, y As Single

Set oPartDocument = CATIA.ActiveDocument
Set oPart = oPartDocument.Part
Set oPartBody = oPart.MainBody






Set Selection1 = CATIA.ActiveDocument.Selection



InPutObjectType(0) = "Point2D"
Status = Selection1.SelectElement2(InPutObjectType, "Selection du point", False)

Set opoint = Selection1.Item(1).Value

Set selection2 = CATIA.ActiveDocument.Selection


InPutObjectType1(0) = "AnyObject"
Status = Selection1.SelectElement2(InPutObjectType1, "Selectionner la ligne lié au point", False)

Set oline = selection2.Item(1).Value



opoint.GetCoordinates apointcoordinates
ainformations(1, 0) = opoint.Name
'ainformations(1, 1) = opoint.GeometricType
ainformations(1, 2) = apointcoordinates(0)
ainformations(1, 3) = apointcoordinates(1)
x = ainformations(1, 2)
y = ainformations(1, 3)

'MsgBox "Nom = " & ainformations(1, 0) & Chr(13) & Chr(13) & "X= " & ainformations(1, 2) & Chr(13) & "Y= " & ainformations(1, 3)

Set oCurrentSketch = oPartBody.Sketches.Item(opoint.Parent.Parent.Name)

Set oFactory2D = oCurrentSketch.OpenEdition

Set oCurrentLine1 = oFactory2D.CreateLine(x, y, x + 100, y + 50)

''contrainte
Dim oRefLine1 As Reference
Set oRefLine1 = oPart.CreateReferenceFromObject(oCurrentLine1)
Dim oRefpoint1 As Reference
Set oRefpoint1 = oPart.CreateReferenceFromObject(opoint)
Dim oRefLine1StartPt As Reference
Set oRefLine1StartPt = oPart.CreateReferenceFromObject(oCurrentLine1.StartPoint)
Dim oRefLine1EndPt As Reference
Set oRefLine1EndPt = oPart.CreateReferenceFromObject(oCurrentLine1.EndPoint)

' Create contraintes
' ------------------



Dim oConstraints As Constraints
Set oConstraints = oCurrentSketch.Constraints
Dim oConstraint As Constraint
Dim oConstraint1 As Constraint
Dim oConstraints2 As Collection

Set oConstraint = oConstraints.AddBiEltCst(catCstTypeOn, oRefpoint1, oRefLine1StartPt)
Set oConstraint1 = oConstraints.AddBiEltCst(catCstTypeDistance, oRefpoint1, oRefLine1EndPt)
oConstraint1.Dimension.Value = 100
oConstraint1.Orientation = catCstOrientOpposite

Set oConstraint2 = oConstraints.AddBiEltCst(catCstTypeAngle, oCurrentLine1, oline)
oConstraint2.Dimension.Value = val_angle
'oConstraint2.Orientation = catCstOrientOpposite

End Sub
Bienvenue
raphael_59240
raphael_59240
actif
actif

Messages : 127
Date d'inscription : 28/03/2015
Age : 53
Localisation : dunkerque

Revenir en haut Aller en bas

R?solu Re: creation de ligne

Message par Contenu sponsorisé


Contenu sponsorisé


Revenir en haut Aller en bas

Revenir en haut


 
Permission de ce forum:
Vous ne pouvez pas répondre aux sujets dans ce forum