INTERSECTION BETWEEN TWO LINES
INTERSECTION BETWEEN TWO LINES
(OP)
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
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






RE: INTERSECTION BETWEEN TWO LINES
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
https://picasaweb.google.com/102257836106335725208
https://picasaweb.google.com/103462806772634246699...
RE: INTERSECTION BETWEEN TWO LINES
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 :)
RE: INTERSECTION BETWEEN TWO LINES
You have to identify them somehow by user selection or by item name....or maybe in same way like you done for name.
Regards
Fernando
https://picasaweb.google.com/102257836106335725208
https://picasaweb.google.com/103462806772634246699...
RE: INTERSECTION BETWEEN TWO LINES
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!!
RE: INTERSECTION BETWEEN TWO 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 SubHere is a reference code
RE: INTERSECTION BETWEEN TWO LINES
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.
indocti discant et ament meminisse periti
RE: INTERSECTION BETWEEN TWO LINES
How can I do that?
RE: INTERSECTION BETWEEN TWO LINES
If you still have a problem, let us know where the trouble is, we'll help you if we can.
indocti discant et ament meminisse periti
RE: INTERSECTION BETWEEN TWO LINES
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 --> Sub
thank you :)
RE: INTERSECTION BETWEEN TWO LINES
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