The code for establishing the substation model is basically established by using the box in part. After establishing the model, coordinate transformation is carried out through the parameters entered by the user.
Code: Select all
DeltaX = FreeCAD.Units.Quantity(self.ui.txtCenterPointX.text()).Value#
DeltaY = FreeCAD.Units.Quantity(self.ui.txtCenterPointY.text()).Value#
DeltaZ = FreeCAD.Units.Quantity(self.ui.txtCenterPointZ.text()).Value#
aBox = FreeCAD.activeDocument().addObject("Part::Box",tmpBoxName)
aBox.Width = FreeCAD.Units.Quantity(self.ui.txtWidth.text()).Value#
aBox.Length = FreeCAD.Units.Quantity(self.ui.txtLength.text()).Value#
aBox.Height = FreeCAD.Units.Quantity(self.ui.txtHeight.text()).Value#
It was recently discovered that the unit of freecad is mm by default.However, I found that units can be modified in preferences.I changed the unit from mm to m in preference, and then returned to freecad and found that the unit of the model did change from mm to m, but the data also changed from 100 to 0.1.
The problem is, in order to avoid repeated modeling, I designed a set of code to rebuild the model after traversing the model, and called different Python codes to rebuild the model according to the properties of the model. For example, now the height data of a fence model in the database is 5, so I think it is 5m high, but when I restore it with code, execute
abox = freecad. Activedocument(). AddObject ("part:: box", tmpboxname) to create a box,
and then
abox Height = freecad.units.quantity (self.ui.txtheight.text()).
The assigned value should be the number 5 read from the database, and when it is displayed in freecad, it will become 0.005M, which is not consistent with my original intention.
A stupid way is that I manually multiply the data in the database by 1000, and then I can import it normally without changing the imported model code. But what if I create a new model? For example, if you build a fence with a height of 6, the database will still save 6 instead of 6000.
So I hope to find a way to use Python scripts, such as abox = freecad Activedocument(). AddObject ("part:: box", tmpboxname) can set the unit when creating a box, so that it can also pass a number of 5 to know whether it is 5m or 5mm. Is there such code?