Personal tools
You are here: Home Forum Use Grouping list elements

Grouping list elements

Up to Use

Grouping list elements

Posted by Said ÇATALBAŞ at August 15. 2021

Hi,

I'm trying to do making group lists elements. I've 3 list (X, Y, Z) and i merge them another list (spheres) for creating coordinates. First 3 element of this spheres list  should be face group. I mean;

spheres[0]: s1

spheres[1]: s2

spheres[2]: s3

But every time I generate that random coordinates, the IDs change. Is there any way to do this right? Any suggestions are appreciated.

Kind regards,

Said.

 
Attachments

Re: Grouping list elements

Posted by Saint Michael at August 16. 2021

Re: Grouping list elements

Posted by Said ÇATALBAŞ at August 21. 2021

Hi Michael,

Thanks for your quick reply. I tried the GetSubShapesID for finding spheres IDs but it returns zero list ([0, 0, 0, 0, 0, 0, 0, 0]). I think spheres are not  sub shape, they are object. What am i missing?

Kind regards,

Said.

Attachments

Re: Grouping list elements

Posted by Saint Michael at August 21. 2021

Hi Said

GetSubShapesID is not in the list of functions I suggested. Use GetInPlace instead, or GetShapesOnSphere()

St.Michael

Attachments

Re: Grouping list elements

Posted by Said ÇATALBAŞ at August 21. 2021

Hi Michael,

First of all, thank you for your help.

IDs = (geompy.SubShapeAllIDs(Cut_1, geompy.ShapeType["FACE"])) with this line im getting all IDs of the geometry. First 3 columns are cylinder's faces. According to my useless mind fourth element should be first sphere's coordinate because first element is the first one which produced. But IDs[3] element is not the first coordinate. I have thousands of sphere in matrix and I want to group first 5 rows (spheres) of that matrix. In short, the first 5 elements of the coordinate matrix and the first 5 spheres produced must have the same IDs. Please let me know if my approach is not correct.

Kind regards,

Said.

Attachments

Re: Grouping list elements

Posted by Saint Michael at August 21. 2021

I'm not sure to understand logic of your approach.  For sure, one can't rely on order of sub-shape IDs.

In my opinion GetInPlace() and GetShapesOnSphere() are most suitable for your task.

St.Michael

Re: Grouping list elements

Posted by Said ÇATALBAŞ at August 21. 2021
Dear Michael,
 
You were right, I misunderstood you. I just change this line as geompy.MakeCompound (sphereFaces[0]) in your code and it worked fine. Now it is just select only the firs coordinate. But they are defined as solid, they have to be defined as faces. Does MakeCompound able to define as face? The other problem i have, when I run the attached script it produce two Cut_1. How to merge them?
 
Best regards,
Said.
Attachments

Re: Grouping list elements

Posted by Saint Michael at August 21. 2021

I don't understand your question about solid.

To suppress publishing Cut_1 twice just remove   geompy.addToStudy( Cut_1, 'Cut_1' )

St.Michael

Attachments

Re: Grouping list elements

Posted by Said ÇATALBAŞ at August 31. 2021

Hi Michael,

I improved the code a bit. Now I group all the spheres at a given height. The demo of the code works correctly but the original code gives this error. Both codes are attached. Thank you for your help.

Traceback (most recent call last):

File "<input>", line 1, in <module>

File "C:/Users/saidc/Desktop/salome_H.py", line 89, in <module>

ids = geompy.GetInPlace(Cut_1, geompy.MakeCompound( sphereFaces ), 1, theName="H_spheres_001")

File "C:\SALOME-9.7.0\W64\GEOM\lib\python3.6\site-packages\salome\salome\geom\geomBuilder.py", line 364, in OpenCallClose

res = theFunction(self, *args, **kwargs)

File "C:\SALOME-9.7.0\W64\GEOM\lib\python3.6\site-packages\salome\salome\geom\geomBuilder.py", line 5976, in GetInPlace

RaiseIfFailed("GetInPlace", self.ShapesOp)

File "C:\SALOME-9.7.0\W64\GEOM\lib\python3.6\site-packages\salome\salome\geom\geomBuilder.py", line 379, in RaiseIfFailed

raise RuntimeError(Method_name + " : " + Operation.GetErrorCode())

RuntimeError: GetInPlace : Error in GEOMAlgo_GetInPlace

 

Best regards,
Said.
Attachments

Re: Grouping list elements

Posted by Said ÇATALBAŞ at September 01. 2021

Hi,

I found where the error is but I don't know how to fix it. If you set the condition more than 20 in demo_2 it gives error.
When I try to group 20 or 10 of the 80 Spheres it works fine, but when I do it for 30 it that error appears.

sphereFaces += geompy.ExtractShapes( Sphere_1, geompy.ShapeType["FACE"])  This line does its job when I set condition to 30,
print(len(sphereFaces))  >>> 30

But I dont know what happens here
ids = geompy.GetInPlace(Cut_1, geompy.MakeCompound( sphereFaces ), 1, theName="H_spheres_001")
 
Any suggestions are appreciated.
 
Best regards,
Said.

 


Attachments

Re: Grouping list elements

Posted by Said ÇATALBAŞ at September 02. 2021

Hi,

I fixed the problem with changing this line:

ids_1 = geompy.GetInPlace(Cut_1, geompy.MakeCompound( sphereFaces ), 1, theName="H_spheres_1")

as:

ids_1 = geompy.GetInPlace(Cut_1, geompy.MakeCompound( sphereFaces ),  theName="H_spheres_1")

Best regards,
Said.
Powered by Ploneboard
Document Actions