- """
- This function cuts any geometry into several subgeometries that are cleanly saved inside the navigation tree with a fully customizable trim size.
- - GeoObj is the geometrical object to be cut and grouped
- - CutPlnLst is a list of plane definitions. Each plane is a 7-tuple (contains 7 values). The first three represent the coordinates of the origin point and the second three represent the coordinates of the normal vector to the plane, the last value corresponds to the trim size of the planes
- Example 1: [(0,0,0,1,0,0,5)]: cut along a plane passing through the origin and normal to the x-axis with a trim size of 5
- Example 2: [(0,0,0,1,0,0,5),(50,0,0,0,1,0,10)]: in addition to the first plane cut, cut through a plane passing by (50,0,0) and normal to the y axis with a trim size of 10
- - OutLvlLst is a list containing integers that represent the inner sectioning level with respect to the original geometry type
- A value of 1 means that the section will provide elements of one level lower than the original type. For example a solid sectioned at level 1 will produce faces. A Face sectioned at level 1 will produce edges.
- A value of 2 means that a deeper sectioning will be applied. A solid sectioned with level 2 will give faces and edges. A face will give edges and vertices. An edge will give only vertices
- The number of elements in this list should be (this is verified in the code) equal to the number of elements in the plane cut list. This is logical.
- Example 1: [1]
- Example 2: [1, 2], This means that the cut over the second plane will produce two types of elements unlike the first cut which will only output the first level objects.
- - PrefixLst is a list of strings that contains the naming Prefixes that are used by the script to generate the subshape names. This is very useful for relating the results to the sectioning requested.
- Example 1: ['Entry']
- Example 2: ['Entry','Exit'] The resulting groups from the sectioning with plane no.1 will then be saved as "Entry_FACE" and/or "Entry_EDGE" according to the original geometry object type and the cutting level
-
- Imagine that we have a solid called ExampleSolid, an example command will be:
- CutnGroup.Go(ExampleSolid,[(0,0,0,1,0,0,5),(50,0,0,0,1,0,10)],[1, 2],['Entry','Exit'])
- """
-
- NumCuts = CheckInput(CutPlnLst, OutLvlLst, PrefixLst, 0)
- OrigType = FindStandType(GeoObj,0)
- InvDictionary = dict((v,k) for k, v in geompy.ShapeType.iteritems()) # Give geometry type name as a function of standard type numbering, ex: 4=FACE, 6=EDGE, 7=VERTEX
- CutPlane = [] ; Sections = [] ; Parts = []
- if NumCuts:
- for i in range(0, NumCuts): # Loop over the cutting planes to create them one by one
- CutPlane.append(CreatePlane(CutPlnLst[i][0:6],CutPlnLst[i][6]))
- OutFather = geompy.MakePartition([GeoObj],CutPlane, [], [],FindStandType(GeoObj,1), 0, [], 0) #Creating the partition object
- if Publish: geompy.addToStudy(OutFather,'SectionedObject')
- for i in range(0, NumCuts):
- for j in range(OrigType+1+2, OrigType+1+2*(OutLvlLst[i]+1),2):
- if j == 8 : j = 7; # Exception for the vertex case (=7)
- PossSubShapesID = geompy.SubShapeAllIDs(OutFather,j) # List of subshape IDs than correspond to the required cutting level (section type : face/wire/vertex)
- PossSubShapes = geompy.ExtractShapes(OutFather,j) # and the corresponding objects
- Accepted = []
- for k in range(0,len(PossSubShapesID)): # Loop over all the subshapes checking if they belong to the cutting plane WITH THE TRIM SIZE CONDITION! if yes add them to current list
- if IsOnPlane(PossSubShapes[k], CutPlnLst[i], 1e-7) and Distance2Pt(geompy.PointCoordinates(geompy.MakeCDG(PossSubShapes[k])),CutPlnLst[i][0:3])<=CutPlnLst[i][-1]:
- Accepted.append(PossSubShapesID[k])
- if Accepted : # If some element is found, save it as a group with the prescribed Prefix
- dummyObj = geompy.CreateGroup(OutFather, j)
- geompy.UnionIDs(dummyObj, Accepted)
- Sections.append(dummyObj)
- if Publish: geompy.addToStudyInFather(OutFather, dummyObj, PrefixLst[i]+"_"+InvDictionary[j][0:2])
- else :
- print "Warning: For the section no.", i, ", No intersection of type " + InvDictionary[j] + " was found. Hence, no corresponding groups were created"
-
- SubShapesID = geompy.SubShapeAllIDs(OutFather,OrigType+1) # Saving also the groups corresponding to the sectioned item of the same type: ex. A solid into n sub-solids due to the sections
- for i in range(0,len(SubShapesID)):
- dummyObj = geompy.CreateGroup(OutFather, OrigType+1)
- geompy.UnionIDs(dummyObj, [SubShapesID[i]])
- Parts.append(dummyObj)
- if Publish: geompy.addToStudyInFather(OutFather, dummyObj, "SB"+"_"+InvDictionary[OrigType+1][0:3]+"_"+str(i+1))
-
- return OutFather, Sections, Parts
- else:
- print("Fatal error, the routine cannot continue any further, check your input variables")
- return -1
+ """
+ This function cuts any geometry into several subgeometries that are cleanly saved inside the navigation tree with a fully customizable trim size.
+ - GeoObj is the geometrical object to be cut and grouped
+ - CutPlnLst is a list of plane definitions. Each plane is a 7-tuple (contains 7 values). The first three represent the coordinates of the origin point and the second three represent the coordinates of the normal vector to the plane, the last value corresponds to the trim size of the planes
+ Example 1: [(0,0,0,1,0,0,5)]: cut along a plane passing through the origin and normal to the x-axis with a trim size of 5
+ Example 2: [(0,0,0,1,0,0,5),(50,0,0,0,1,0,10)]: in addition to the first plane cut, cut through a plane passing by (50,0,0) and normal to the y axis with a trim size of 10
+ - OutLvlLst is a list containing integers that represent the inner sectioning level with respect to the original geometry type
+ A value of 1 means that the section will provide elements of one level lower than the original type. For example a solid sectioned at level 1 will produce faces. A Face sectioned at level 1 will produce edges.
+ A value of 2 means that a deeper sectioning will be applied. A solid sectioned with level 2 will give faces and edges. A face will give edges and vertices. An edge will give only vertices
+ The number of elements in this list should be (this is verified in the code) equal to the number of elements in the plane cut list. This is logical.
+ Example 1: [1]
+ Example 2: [1, 2], This means that the cut over the second plane will produce two types of elements unlike the first cut which will only output the first level objects.
+ - PrefixLst is a list of strings that contains the naming Prefixes that are used by the script to generate the subshape names. This is very useful for relating the results to the sectioning requested.
+ Example 1: ['Entry']
+ Example 2: ['Entry','Exit'] The resulting groups from the sectioning with plane no.1 will then be saved as "Entry_FACE" and/or "Entry_EDGE" according to the original geometry object type and the cutting level
+
+ Imagine that we have a solid called ExampleSolid, an example command will be:
+ CutnGroup.Go(ExampleSolid,[(0,0,0,1,0,0,5),(50,0,0,0,1,0,10)],[1, 2],['Entry','Exit'])
+ """
+
+ NumCuts = CheckInput(CutPlnLst, OutLvlLst, PrefixLst, 0)
+ OrigType = FindStandType(GeoObj,0)
+ InvDictionary = {v: k for k, v in geompy.ShapeType.items()} # Give geometry type name as a function of standard type numbering, ex: 4=FACE, 6=EDGE, 7=VERTEX
+ CutPlane = [] ; Sections = [] ; Parts = []
+ if NumCuts:
+ for i in range(0, NumCuts): # Loop over the cutting planes to create them one by one
+ CutPlane.append(CreatePlane(CutPlnLst[i][0:6],CutPlnLst[i][6]))
+ OutFather = geompy.MakePartition([GeoObj],CutPlane, [], [],FindStandType(GeoObj,1), 0, [], 0) #Creating the partition object
+ if Publish: geompy.addToStudy(OutFather,'SectionedObject')
+ for i in range(0, NumCuts):
+ for j in range(OrigType+1+2, OrigType+1+2*(OutLvlLst[i]+1),2):
+ if j == 8 : j = 7; # Exception for the vertex case (=7)
+ PossSubShapesID = geompy.SubShapeAllIDs(OutFather,j) # List of subshape IDs than correspond to the required cutting level (section type : face/wire/vertex)
+ PossSubShapes = geompy.ExtractShapes(OutFather,j) # and the corresponding objects
+ Accepted = []
+ for k in range(0,len(PossSubShapesID)): # Loop over all the subshapes checking if they belong to the cutting plane WITH THE TRIM SIZE CONDITION! if yes add them to current list
+ if IsOnPlane(PossSubShapes[k], CutPlnLst[i], 1e-7) and Distance2Pt(geompy.PointCoordinates(geompy.MakeCDG(PossSubShapes[k])),CutPlnLst[i][0:3])<=CutPlnLst[i][-1]:
+ Accepted.append(PossSubShapesID[k])
+ if Accepted : # If some element is found, save it as a group with the prescribed Prefix
+ dummyObj = geompy.CreateGroup(OutFather, j)
+ geompy.UnionIDs(dummyObj, Accepted)
+ Sections.append(dummyObj)
+ if Publish: geompy.addToStudyInFather(OutFather, dummyObj, PrefixLst[i]+"_"+InvDictionary[j][0:2])
+ else :
+ print("Warning: For the section no.", i, ", No intersection of type " + InvDictionary[j] + " was found. Hence, no corresponding groups were created")
+
+ SubShapesID = geompy.SubShapeAllIDs(OutFather,OrigType+1) # Saving also the groups corresponding to the sectioned item of the same type: ex. A solid into n sub-solids due to the sections
+ for i in range(0,len(SubShapesID)):
+ dummyObj = geompy.CreateGroup(OutFather, OrigType+1)
+ geompy.UnionIDs(dummyObj, [SubShapesID[i]])
+ Parts.append(dummyObj)
+ if Publish: geompy.addToStudyInFather(OutFather, dummyObj, "SB"+"_"+InvDictionary[OrigType+1][0:3]+"_"+str(i+1))
+
+ return OutFather, Sections, Parts
+ else:
+ print("Fatal error, the routine cannot continue any further, check your input variables")
+ return -1