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!

INTERSECTION BETWEEN TWO LINES

Status
Not open for further replies.

mayrou

Electrical
Jan 8, 2014
55
TN
Hello world
I am beginner in VB and i would like to create macro in CATIA which create a point intersection between two lines
in the beginning the macro extract two lines (line 1 and line 2)from the tree of specification

Dim documents1 As Documents
Set documents1 = CATIA.Documents

Dim partDocument1 As Document
Set partDocument1 = documents1.Item(name)

Dim part1 As Part
Set part1 = partDocument1.Part

Dim hybridShapeFactory1 As Factory
Set hybridShapeFactory1 = part1.HybridShapeFactory

Dim bodies1 As Bodies
Set bodies1 = part1.Bodies

Dim body1 As Body
Set body1 = bodies1.Item("Points dans système d'axes.1")

Dim reference1 As Reference
Set reference1 = part1.CreateReferenceFromObject(line1)

Dim reference2 As Reference
Set reference2 = part1.CreateReferenceFromObject(line2)

Dim hybridShapeIntersection1 As HybridShapeIntersection
Set hybridShapeIntersection1 = hybridShapeFactory1.AddNewIntersection(reference1 , reference2)

hybridShapeIntersection1.PointType = 0

hybridShapeIntersection1.IntersectMode = True

hybridShapeIntersection1.ExtendMode = 3

hybridBody1.AppendHybridShape hybridShapeIntersection1

part1.InWorkObject = hybridShapeIntersection1

part1.Update

This program is wrong please anyone can help me!!!!!!!!!!!!!!! :(

Thanks [love2]



 
Replies continue below

Recommended for you

Hi,

Looking quick over your code and I saw several problems...how do you get what is in red color ?

Set partDocument1 = documents1.Item(name)
................
Dim reference1 As Reference
Set reference1 = part1.CreateReferenceFromObject(line1)

Dim reference2 As Reference
Set reference2 = part1.CreateReferenceFromObject(line2)




Regards
Fernando

 
hi!
i meant by "name" the control name that i work with and i have no problem with it!
line1 and line2 are two geometric elements extracted from the tree of specification exactly from sketches
so how can i call these two lines and create the intersection point!
thx o lot :)
 
i already selected a part in an assembly, then i search a specific line in this part "line.3" in "sketch.6" then same operation with the second selected part!
this is a part of my new code

Dim sketches1 As Sketches
Set sketches1 = body1.Sketches

Dim sketch1 As Sketch
Set sketch1 = sketches1.Item("Esquisse.6")

Set geometricElements1 = sketch1.GeometricElements

For i= 1 To geometricElements1.count
Set objParameter = geometricElements1.Item(i)

strParmName1 = objParameter.Name
if InStr(strParmName1 ,"Line.3") <>0 then
line1 = strParmName1
End If
Next

Dim reference1 As Reference
Set reference1 = Part1.CreateReferenceFromObject(objParameter)

Dim reference2 As Reference
Set reference2 = part1.CreateReferenceFromObject(objparameter2)

Dim hybridShapeIntersection1 As HybridShapeIntersection
Set hybridShapeIntersection1 = hybridShapeFactory1.AddNewIntersection(reference1, reference2)

don't know where the problem lies!!

 
I think it is not possible to do the intersection with the sketch lines.

Code:
Sub Alex()

Dim partDocument1 As Document
Set partDocument1 = CATIA.ActiveDocument

Dim part1 As Part
Set part1 = partDocument1.Part

Dim body1 As Body
Set body1 = part1.Bodies.Item("PartBody")

Dim sketches1 As Sketches
Set sketches1 = body1.Sketches

Dim bodies1 As Bodies
Set bodies1 = part1.Bodies

Set hybridBodies1 = part1.HybridBodies
Set hybridBody1 = hybridBodies1.Add()

Dim sketch1 As Sketch
Set sketch1 = sketches1.Item("Sketch.1")
Set geometricElements1 = sketch1.GeometricElements

For i = 1 To geometricElements1.Count
Set objParameter = geometricElements1.Item(i)

strParmName1 = objParameter.Name
If InStr(strParmName1, "Line.1") <> 0 Then
line1 = strParmName1
Set JOE = geometricElements1.GetItem(line1)
End If

Next i


Dim sketch2 As Sketch
Set sketch2 = sketches1.Item("Sketch.2")
Set geometricElements1 = sketch2.GeometricElements

For i = 1 To geometricElements1.Count
Set objParameter = geometricElements1.Item(i)

strParmName2 = objParameter.Name
If InStr(strParmName2, "Line.1") <> 0 Then
line2 = strParmName2
Set JOE2 = geometricElements1.GetItem(line2)

End If

Next i


Set hybridShapeFactory1 = part1.HybridShapeFactory

Dim reference1 As Reference
Set reference1 = part1.CreateReferenceFromObject(JOE)

Dim reference2 As Reference
Set reference2 = part1.CreateReferenceFromObject(JOE2)

Dim hybridShapeIntersection1 As HybridShapeIntersection
Set hybridShapeIntersection1 = hybridShapeFactory1.AddNewIntersection(reference1, reference2)
hybridShapeIntersection1.PointType = 0

hybridShapeIntersection1.IntersectMode = True

hybridShapeIntersection1.ExtendMode = 3

hybridBody1.AppendHybridShape hybridShapeIntersection1

part1.InWorkObject = hybridShapeIntersection1

'part1.Update
End Sub

Here is a reference code
 

mayrou said:
i search a specific line in this part "line.3" in "sketch.6"

I do not think it is possible to use internal sketch element (a line in a sketch) as source for any construction outside the sketch.

You have to use the sketch edge definition of the internal line or define and use the line as an output feature.

Manually I can not create an intersection point between 2 sketch lines from 2 sketches, but I can if thoses line are defined as output feature.

Eric N.
indocti discant et ament meminisse periti
 
search online doc for sketch output feature.

If you still have a problem, let us know where the trouble is, we'll help you if we can.

Eric N.
indocti discant et ament meminisse periti
 
Hi!! :)
I made some modifications in my code!
In fat, what I want exactly is to extract the neutral fiber from a first selected part (part1) and the second one from other selected part (part2).
Then I want to create the intersection of these two lines (neutral fiber1, neutral fiber2) found in SKETCH.6
The intersection point will be placed in a 3rd part (control part)
Code:
After execution, it make an intersection but inactive or empty!
thank you :)
 

Dim documents1 As Documents
Set documents1 = CATIA.Documents

Dim partDocument1 As Document
Set partDocument1 = documents1.Item(controlname)

controleFile = Replace(CATIA.ActiveDocument.FullName, ".CATProduct", "_Controle.CATPart")

Set controleDoc = CATIA.Documents.Read(controleFile)

Set part3 = controleDoc.Part

Dim hybridShapeFactory1 As Factory
Set hybridShapeFactory1 = part.HybridShapeFactory

Dim bodies1 As Bodies
Set bodies1 = part.Bodies

Dim body1 As Body
Set body1 = bodies1.Item("Corps principal")

Dim sketches1 As Sketches
Set sketches1 = body1.Sketches

Dim sketch1 As Sketch
Set sketch1 = sketches1.Item("Esquisse.6")

Set geometricElements1 = sketch1.GeometricElements

For i= 1 To geometricElements1.count
Set objParameter = geometricElements1.Item(i)

strParmName1 = objParameter.Name
if InStr(strParmName1 ,"Fibre neutre") <>0 then
line1 = strParmName1
End If
Next

Dim reference1 As Reference
Set reference1 = part.CreateReferenceFromObject(objParameter)

Dim reference2 As Reference
Set reference2 = part2.CreateReferenceFromObject(objParameter2)

'Dim hybridShapeIntersection1 As HybridShapeIntersection
'Set hybridShapeIntersection1 = hybridShapeFactory1.AddNewIntersection(reference1, reference2)

'hybridShapeIntersection3.PointType = 0

'hybridShapeIntersection3.IntersectMode = True

'hybridShapeIntersection3.ExtendMode = 3

Set bodies3 = part3.Bodies

Set body3 = bodies3.Item("Corps principal")

Set hybridShapeFactory3 = part3.HybridShapeFactory

Set hybridShapeIntersection3 = hybridShapeFactory3.AddNewIntersection(reference1, reference2)

body3.InsertHybridShape hybridShapeIntersection3

hybridShapeIntersection3.Name = "nouvelle intersection"

part3.InWorkObject = hybridShapeIntersection3

part3.Update

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top