Das Wissen aller Anwender nutzen

Im Allplan Connect Forum tauschen sich Anwender aus, geben wertvolle Tipps oder beraten sich bei ganz konkreten Aufgabenstellungen − auch international.
Und damit wirklich keine Frage unbeantwortet bleibt, unterstützen die Mitarbeiter des Technischen Supports ebenfalls aktiv das Forum.

Es erwarten Sie:

  • Foren-Vielfalt aus CAD Architektur, CAD Ingenieurbau uvm.
  • Tipps von User für User
  • international: Deutsch, Englisch, Italienisch, Französisch und Tschechisch

Melden Sie sich jetzt an und diskutieren Sie mit!

Zur Registrierung

[Frage] Is that possible to modify the length of an existing cuboid using PythonPart?


Hello everyone,

I have a question about modification.

I want to find a way to modify an existing 3D model. I have create a cuboid. But when I want to change the properties such as length or height, which were set at the time of creation, I found it's the class of BRep. I can not find a way to change those properties. I can only cut it etc. The function of CreateCuboid or CreateCylinder returns class of BRep.

Is that possible to change the length or height directly? Or how to convert the class of the geometry from BRep to Class of Cuboid? So I can use the function of Cuboid to set the attributes.

thanks in advance.

Best

Anhänge (1)

Typ: image/png
28-mal heruntergeladen
Größe: 57,39 KiB

Hilfreichste Antwort anzeigen Hilfreichste Antwort verbergen

Zitiert von: ZihanDeng
Hi,
Thanks for your quick reply!
Just as you said, what I want is using PythonPart to change the attributes that I've assigned. For example I have defined a cuboid with 3000,3000,3000. But now I want to change those attributes to maybe 3000,2000,1000 using python parts.
I have already used the ElementsAttributesServer but what I got from GetAttributes is an empty list of attributes.Is that means I need to define the Length or Height again?
Thanks!
Best

Hi!

If you created the cuboid using native Allplan function, or created the cuboid with a python script, without putting it into a PythonPart container at the end of your script, the information about length, width and height is lost. When the cuboid is created in the drawing file, it is saved as a collection of 8 vertices, 12 edges and 6 faces. To be more specific, from that moment its geometry is described with a Polyhedron3D object. There is a way to modify the coordinates of those vertices or generally perform geometrical operations on that cuboid. But this is complicated, and is not just changing a value of height. Cuboid3D is an object, that you can use to create a cuboid only, but after that it is just a Polyhedron3D.

As Christophe mentioned, you can create a parametric object: a PythonPart. In this case you will not lose this information after creation. It will be kept in PythonPart parameters. Optionally it can be kept also in Attributes.

If you want to go the first way: modifying the vertices of a Polyhedron: we will soon publish some examples showing how you can modify a geometry. But I recommend the second way: create a PythonPart at the end of the script.

Best regards,
Bart

1 - 10 (13)

Hi,

I think the best way is to work with parametric object not a simple 3d model.

When you define your object (cuboid in your case) you can assign attributes such as length.

Then, these attributes can be modified in various ways (like here).

Can you tell us more about your needs ?

Best

Hi,

Thanks for your quick reply!

Just as you said, what I want is using PythonPart to change the attributes that I've assigned. For example I have defined a cuboid with 3000,3000,3000. But now I want to change those attributes to maybe 3000,2000,1000 using python parts.

I have already used the ElementsAttributesServer but what I got from GetAttributes is an empty list of attributes.Is that means I need to define the Length or Height again?

Thanks!

Best

Hi,

First you can create a cuboid defined by Length, Width and Height.

			<Parameter>
				<Name>CubLength</Name>
				<Text>Length</Text>
				<Value>1000</Value> <!-- be careful with the type of variable -->
				<ValueType>Attribute</ValueType>
				<AttributeId>5008</AttributeId> <!-- custom attribute -->
			</Parameter>

			<Parameter>
				<Name>CubWidth</Name>
				<Text>Width</Text>
				<Value>1000.0</Value>
				<ValueType>Attribute</ValueType>
				<AttributeId>221</AttributeId>
			</Parameter>

			<Parameter>
				<Name>CubHeight</Name>
				<Text>Height</Text>
				<Value>1000.0</Value>
				<ValueType>Attribute</ValueType>
				<AttributeId>222</AttributeId>
			</Parameter>

    # Extract parameters values from palette
    cub_length = build_ele.CubLength.value
    cub_width  = build_ele.CubWidth.value
    cub_height = build_ele.CubHeight.value

    # Create object
    placement = Geometry.AxisPlacement3D(Geometry.Point3D(),
                                         Geometry.Vector3D(1, 0, 0),
                                         Geometry.Vector3D(0, 0, 1)
                                         )
    cub_geo   = Geometry.BRep3D.CreateCuboid(placement, cub_length, cub_width, cub_height)

Please note : I'm using a custom attribute for the length.

Then you can modify it with a second script (example in visual with AttributeModifier)

The PythonPart will be updated when you double click on it, I'm looking for a solution to mass update........

Best

Anhänge (2)

Typ: image/jpeg
58-mal heruntergeladen
Größe: 56,50 KiB
Typ: image/jpeg
52-mal heruntergeladen
Größe: 23,07 KiB

Zitiert von: ZihanDeng
Hi,
Thanks for your quick reply!
Just as you said, what I want is using PythonPart to change the attributes that I've assigned. For example I have defined a cuboid with 3000,3000,3000. But now I want to change those attributes to maybe 3000,2000,1000 using python parts.
I have already used the ElementsAttributesServer but what I got from GetAttributes is an empty list of attributes.Is that means I need to define the Length or Height again?
Thanks!
Best

Hi!

If you created the cuboid using native Allplan function, or created the cuboid with a python script, without putting it into a PythonPart container at the end of your script, the information about length, width and height is lost. When the cuboid is created in the drawing file, it is saved as a collection of 8 vertices, 12 edges and 6 faces. To be more specific, from that moment its geometry is described with a Polyhedron3D object. There is a way to modify the coordinates of those vertices or generally perform geometrical operations on that cuboid. But this is complicated, and is not just changing a value of height. Cuboid3D is an object, that you can use to create a cuboid only, but after that it is just a Polyhedron3D.

As Christophe mentioned, you can create a parametric object: a PythonPart. In this case you will not lose this information after creation. It will be kept in PythonPart parameters. Optionally it can be kept also in Attributes.

If you want to go the first way: modifying the vertices of a Polyhedron: we will soon publish some examples showing how you can modify a geometry. But I recommend the second way: create a PythonPart at the end of the script.

Best regards,
Bart

Hello!

Thank you for your reply! I finally understood why the height value was missing. I checked the type of the cube created. It is actually Polyhedron3D or BRep3D.

I tried to modify the geometry directly. But then the attributes I set would not be modified (or had disappeared). What I want to do is the modification of the attributes

Thanks for the explanation and sorry for replying so late Christophe. but I don't understand what is the next step to create the PythonPart at the end of the script. I'm sorry, I did not understand how to create a parametric object

Another question related to this is that I noticed that there are functions that can set Cuboid properties directly, such as SetHeight(height). So, can I keep the type of Cuboid3D instead of Polyhedron3D or BRep3D or can we set the type of the class from Polyhedron3D to Cuboid3D?

Thanks again for your explanation and reply!

Best Regards,
Zihan

For my better understanding I have few questions:

  • You are currently trying to create an Interactor PythonPart, right? Not a standard PythonPart
  • The user journey looks like: 1 - setting desired length/width/etc. in the palette; 2 - selecting a cube in the model. Is that right?
  • Was the cube created by another Python script or using the native Allplan function Box
If I know the answers, I think i will be able to better understand your goal.

Best regards,

Hi,

1-Right it's Interactor PythonPart
2-What I want to do is, firstly the users select a cube in the model, then users can set the values of length etc in the palette
3-The cube was created by Python script I created

Thank you very much!

Best Regards,

Ok, well then of course there are more than one solution to your problem

  • Put the cube into a parametric container, called PythonPart, already when it is created. Your Python script for the creation could be then a standard PythonPart.
  • Create a second interactor PythonPart for modification only, that analyze the geometry of selected solid

The first option will be much easier regarding the effort. You are however limited regarding bulk modification of multiple PythonParts at once. If that is not an issue for you, I would recommend this way.

The second way is much more difficult, because as I said in the moment you terminate you creation script you create a Polyhedron3D in the model. And this object is only a collection of points (vertices). You have no idea, if those points together are a cuboid. You would have to analyze the geometry. Also, the information about the orientation gets lost: you don't where is the length, width and height anymore. The geometry object of Type Polyhedron3D does not store this information. At least not in that simple way.

Those are the two ways, that comes to my mind now. There may be more Let me know, which one you chose, so I could give you more tips.

Best regards,
Bart

BTW if you really want to dig into how a polyhedron is constructed, you can try to construct one point-by-point with this example

1 - 10 (13)