Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

New to Catia VB, creating intersection

Status
Not open for further replies.

Reubot

Aerospace
Apr 25, 2017
5
Hello everybody,

I am new to this forum and new to CATIA VBscripting/VBA and Im having some difficulty understanding some concepts. I hope someone here will be so kind to explain a few things to me.

I recorded a macro that intersects a line with a surface (see code below).

1. Now the first thing I don't understand is why the first element, the line, is defined as a parameter. Could anyone explain to me why this is done like this? Is it not just a hybridshape like the surface?
2. The second thing I am having trouble with is that in my part I have another geometrical set of lines which have been created earlier, now when I rerun the macro the line in that set is selected for the intersect, how do I control this? I have been trying to figure out a way to properly reference this but have not been able to figure it out.
3. What does the PointType property control and what other options are there? the catia documentation only gives me the following:

Property PointType( ) As long

Returns or sets the PointType flag for intersect.


Code:
Language="VBSCRIPT"

Sub CATMain()

Set documents1 = CATIA.Documents
Set partDocument1 = documents1.Item("Part1.CATPart")
Set part1 = partDocument1.Part
Set hybridShapeFactory1 = part1.HybridShapeFactory
Set parameters1 = part1.Parameters
Set hybridShapeLineExplicit1 = parameters1.Item("Line.1")
Set reference1 = part1.CreateReferenceFromObject(hybridShapeLineExplicit1)

Set hybridShapeOffset1 = part1.HybridBodies.Item("GeoSet1").HybridBodies.Item("GeoSet2").HybridShapes.Item("Offset.Surface")
Set reference2 = part1.CreateReferenceFromObject(hybridShapeOffset1)
Set hybridShapeIntersection1 = hybridShapeFactory1.AddNewIntersection(reference1, reference2)
hybridShapeIntersection1.PointType = 0

Set hybridBody3 = part1.HybridBodies.Item("GeoSet1").HybridBodies.Item("GeoSet2").HybridBodies.Item("GeoSet3")
hybridBody3.AppendHybridShape hybridShapeIntersection1
part1.InWorkObject = hybridShapeIntersection1
part1.Update 

End Sub

Any help is highly appreciated.

Thanks
 
Replies continue below

Recommended for you

It would be easier to help if you said what you want the macro to do and if you had a picture of your specification tree so we can see the structure. Will the tree look the same all the time?

1. The first "element" in the line is a parameter because the line likely has no history. Does the line have a red lightning bolt on it...it is not modifiable? If so, CATIA considers these elements parameters. If the line had history, it would not appear as a parameter.

2. I am not sure what you are asking here. Do you want to have the next line intersected each time the macro is run? If so, you can just set up a loop. I would need the tree to understand the structure.
But, if you had a part with one geoset called "Lines" and another geoset called "Intersects" you could do something like the following (the code is not complete and will not work...it is just an example. If you give more details, we can try to get something that works for you.

Code:
'Declare the geosets where you will get lines and store intersects
Dim oLinesGeoset as HybridBody
Dim oIntersectsGeoset as HybridBody

'set the geosets
set oLinesGeoset = CATIA.ActiveDocument.Part.HybridBodies.Item("Lines")
set oIntersectsGeoset = CATIA.ActiveDocument.Part.HybridBodies.Item("Intersects")

Dim oLine as AnyObject 'I'm not sure what the line type

For i = 1 to oLinesGeoset.hybridshapes.count
[indent]
'Get the next line to intersect
Set oLine= oLinesGeoset.Hybridshapes.item(i)

'Make a reference to the line
Set reference1 = CATIA.ActiveDocument.Part.CreateReferenceFromObject(oLine)

'make an intersect
Set hybridShapeIntersection1 = hybridShapeFactory1.AddNewIntersection(reference1, reference2)

'Store the intersect in the intersects geoset
oIntersectsGeoset.AppendHybridShape hybridShapeIntersection1

'Local update the intersect
hybridShapeIntersection1.Compute
[/indent]

Next

3. I am not sure what PointType does
 
Hi Lardman,

Thanks for your reply, I highly appreciate it.

What Im trying here is only part of a slightly bigger project. Ultimately I want to copy and paste a selected part multiple times and constrain it to a user selected set of geometry (note im working in a product). So the idea is that the user selects a bunch of lines (using SelectElement3 method) and a (curved) mating surface. The macro will then create an intersection with the line and surface, the resulting point will be used to constrain the copied part as well as the original line.
Initially my idea was to ask the user to select lines as well as points and then match these, but I was having difficulty matching the line to the correct point, the result was that the copied parts were flying around in space. The other issue I ran into here is the same as point 2 where I couldn't figure out how to properly reference the line, e.g. There are two lines named Line.1 in my part, but these are in different geo. sets. I think CATIA has another internal naming of features besides the one displayed in the tree?? it looked like the macro was selecting the first line made...

My intention is to eventually set-up a loop and then go through all the lines selected by the user, I was just trying to get the intersection part right first.

My tree (for this initial test) looks something like this:

Capture_mjg29w.png


There is another part still in the product that cant be seen on the screenshot, the line I want to refer to is in the set Lines2, whereas another line with the same name exists in Lines1. (although I would also use the tool for the lines in 'Lines1')

I want to be able to use the tool for different projects and allow the user to select the lines he/she wants therefore there is no guarantee the tree will look the same everytime

To get back to point 1. thanks, indeed it is an isolated element so at least that's cleared up :)


Thanks again for your help
 
working with user selection could actually make it easier.

step 1 check if selection is already filled with lines and 1 surface, if not ask user to make selection and check content (x lines and 1 surface) when done.

for each line in selection create intersection with selected surface

you can start with the following code and finish it...

Code:
    Private surfRef As Reference
    Private lineRefCollection As Collection
    
    Sub CATMain()

    selectionOK = Fasle
    Set lineRefCollection = New Collection
    
    
    If CATIA.ActiveDocument.Selection.Count2 > 2 Then selectionOK = checkSelection()
    
    ' you do the SelectElement2 here
    ' but you can check selection again to make sure you have line(s) and one surface
    
    If selectionOK = False Then End
    
    Dim HSF As HybridShapeFactory
    Set HSF = CATIA.ActiveDocument.Part.HybridShapeFactory
    
    Set hybridBody3 = CATIA.ActiveDocument.Part.HybridBodies.Item("GeoSet1").HybridBodies.Item("GeoSet2").HybridBodies.Item("GeoSet3")

    For Each refLine In lineRefCollection
    
        Set hybridShapeIntersection1 = HSF.AddNewIntersection(refLine, surfRef)
        
        hybridBody3.AppendHybridShape hybridShapeIntersection1
    
    Next refLine
    
    CATIA.ActiveDocument.Part.Update

End Sub


Function checkSelection() As Boolean

    checkSelection = Fasle
    
    Dim theSel As Selection
    Set theSel = CATIA.ActiveDocument.Selection
    
    nbFace = 0
    nbLine = 0
    
    For i = 1 To theSel.Count2
    
        itemTypeName = TypeName(theSel.Item2(i).Value)
    
        
        Select Case itemTypeName
        
            Case "Face", "PlanarFace"
                nbFace = nbFace + 1
                Set surfRef = theSel.Item2(i).Reference
            
            Case "HybridShapeLineExplicit", "HybridShapeLinePtPt", "RectilinearMonoDimFeatEdge", _
            "HybridShapeLineExplicit", "RectilinearTriDimFeatEdge", "RectilinearBiDimFeatEdge"
            ' You add all type of line/rectiline edge you want above
            
                nbLine = nbLine + 1
                lineRefCollection.Add theSel.Item2(i).Reference
                
        
        End Select
    
    Next
    
    If nbLine >= 1 And nbFace = 1 Then checkSelection = True

End Function


Eric N.
indocti discant et ament meminisse periti
 
.PointType is used to get/set the following option:

PointType_sqqbbb.png


sorry for big picture i just realized it is because I have 4K screen and scale 200%. I'll try to reduce size next time :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor