×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

INTERSECTION BETWEEN TWO LINES

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 love2



RE: INTERSECTION BETWEEN TWO LINES

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

https://picasaweb.google.com/102257836106335725208
https://picasaweb.google.com/103462806772634246699...

RE: INTERSECTION BETWEEN TWO LINES

(OP)
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 :)

RE: INTERSECTION BETWEEN TWO LINES

(OP)
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!!

RE: INTERSECTION BETWEEN TWO LINES

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

RE: INTERSECTION BETWEEN TWO LINES


Quote (mayrou)

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

RE: INTERSECTION BETWEEN TWO LINES

(OP)

Quote (AlexLozoya )

Set JOE = geometricElements1.GetItem(line1)
getitem method failed!!

Quote (itsmyjob )

if thoses line are defined as output feature.
How can I do that?

RE: INTERSECTION BETWEEN TWO LINES

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

RE: INTERSECTION BETWEEN TWO LINES

(OP)
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 --> Sub

 
After execution, it make an intersection but inactive or empty!
thank you :)

RE: INTERSECTION BETWEEN TWO LINES

(OP)

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources