Previously, we learned how to create an object (a line with fixed length) via the PythonParts API. Today I’m going to show you how to set up handles for our HelloWorld script…

1) GUI Script

The handle that we are going to create will allow us to interact with a variable called Length.

So we need to create it in the palette.

I take my HelloWorld.pyp file and, between the Element tags, I first generate a page :

<Page>

<Name>Page1</Name>
<Text>Général</Text>

</Page>

Please note :

  • the pages corresponding to the different tabs in the palette ;
  • we give it a name Page1 and I place some text that shows up in Allplan : Général ;
  • the pages’ name is displayed from the 2nd tab.

Then, into my Page1, I place the fields to insert my variable :

<Parameter>
<Name>LineLength</Name>
<Text>Longueur</Text>
<Value>1000.0</Value>
<ValueType>Length</ValueType>
</Parameter>

Let’s look at it :

  • Parameter

Required tag, it’s the source of all our variables.

  • Name

The ID, it must be unique because it will be called in our main scripts.

  • Text

The text that is displayed in Allplan.

  • Value

We set a default value for our variable, here “1000”.

  • ValueType

Finally, the type of variable we want to use.

Please note :

  • there is a lot of possibilities (integer, list, …) ; feel free to look at the PythonPart AllControls (C:\ProgramData\Nemetschek\Allplan\2023\Etc\Examples\PythonParts\PaletteExamples) or this link ;
  • Name (must be unique), Text and ValueType are the 3 required fields for any parameter.

Here is the complete source code :

2) Main Script

We start by import the needed modules into our Python script :

from HandlePropertiesService import HandlePropertiesService
from HandleDirection import HandleDirection
from HandleParameterData import HandleParameterData
from HandleParameterType import HandleParameterType
from HandleProperties import HandleProperties

We create a new function move_handle that will listen to any modification on the handle :

def move_handle(build_ele, handle_prop, input_pnt, doc):

 

HandlePropertiesService.update_property_value(build_ele, handle_prop, input_pnt)

 

return create_element(build_ele, doc)

I go into my create_element function, and I initialize my list of handles :

handle_list = []

Don’t forget to add this list to my return statement :

return CreateElementResult(model_ele_list, handle_list)

Then, I extract the informations from the palette :

# Extract parameters values ​​from palette
line_length = build_ele.LineLength.value

Please note : here is the Name field of the GUI script.

I modify my 2D line by replacing the fixed length (1000) by my variable line_length :

# Create 2D line
line = Geometry.Line2D(0, 0, line_length, 0)

Finally, I create my handle :

# Create the handles
handle_length = HandleProperties(« LineLengthHandle »,
Geometry.Point3D(line_length, 0, 0),
Geometry.Point3D(),
[HandleParameterData(« LineLength », HandleParameterType.POINT_DISTANCE)],
HandleDirection.X_DIR
)

 

handle_length.info_text = « Longueur »
handle_list.append(handle_length)

Let’s look in detail :

 

  • first I name this variable : handle_length ;
  • I give an ID for my handle LineLengthHandle ;
  • I set the final point Geometry.Point3D(line_length, 0, 0) ;
  • I set the first point (Geometry.Point3D() ;
  • I associate it with my LineLength variable of the GUI script ;
  • I freeze the direction along the X axis with HandleDirection.X_DIR ;
  • for a better user experience I can add a text to my handle (displayed in Allplan) ;
  • Finally, I add my handle to my set with handle_list.append(handle_length).

Here is the complete source code :

My simple line became interactive with an input field for the length and my handle is now functional :

0 Comments

Submit a Comment

Objects3D V2.0

Next step for the modeling of our PythonPart “Reinforced Concrete Column”, today let's see how to configure the anchors of our 3D object. By anchoring I am particularly thinking of 2 types :...

Objects3D V1.0

New series in the PythonParts learning journey, let's delve into the modeling of a 3D object : a reinforced concrete column.1) GUI ScriptIn this example, we will set up the initial fields required...

Objects2D V3.0

Last step for this PythonParts example, I'll show you how to set up a legend for our object. This should include the following information : my object's name ; the name of a characteristic geometric...

Objects2D V2.0

In the previous article, we saw how to prepare our code in OOP, today let's see how to exploit its potential with this new example. Indeed, we are going to complete our PythonPart in order to...

Objects2D V1.0

We will build more complex objects on Allplan software, but first at all a word about Object Oriented Programming (OOP)...1) Object Oriented ProgrammingObject Oriented Programming (called OOP) is a...

HelloWorld V3.0

Last step for our HelloWorld script, we will see how to customize the rendering of our object.1) GUI ScriptBack in our palette, I first create a chapter to dissociate the geometric controls from...

HelloWorld V1.0

HelloWorld is traditionally written to provide an example of a programming language. We will be no exception here with our first script's writing. The goal is simple, create a line with fixed...

Structure of PythonParts

Allplan is installed, your IDE is ready... perfect, let's see in detail how PythonParts work.1) Files' DescriptionTo work, a PythonPart needs at least 2 files : GUI File The interface file...

Introduction

In this series of articles, we'll study the editing of scripts in the Python programming language for the Allplan software.To allow you to follow these tutorials properly, I'm going to make a few...