Code: Select all
import FreeCAD, FreeCADGui, Part
import pivy
from pivy import coin
import numpy
class AConductor:
def __init__(self, obj):
"Add some custom properties to our box feature"
obj.addProperty("App::PropertyVectorList","PointsList","EM Para", "电荷点集合").PointsList=FreeCAD.PointsList
obj.Proxy = self
def execute(self, fp):
print("class AConductor: execute called")
def onChanged(self, vp, prop):
print("class AConductor: def onChanged called")
theLine = FreeCAD.ActiveDocument.getObject("ModelConductor_XXX")
print("theLine name is:" + theLine.Name)
theLine.PointsList[50].x=111
theLine.PointsList[50].y=222
theLine.PointsList[50].z=333
print("theLine.PointsList[50].x is:" + str(theLine.PointsList[50].x))
print("theLine.PointsList[50].y is:" + str(theLine.PointsList[50].y))
print("theLine.PointsList[50].z is:" + str(theLine.PointsList[50].z))
print("class AConductor: def onChanged end")
Code: Select all
d = FreeCAD.activeDocument()
f = d.addObject("Mesh::FeaturePython", "ModelConductor_XXX") # Create a mesh feature
f.Mesh = ASubConductorMesh # Assign the mesh object to the internal property
from CConductor import AConductor,ViewProviderAConductor
AConductor(f)
ViewProviderAConductor(f.ViewObject)
d.recompute()
In function "def onChanged(self, vp, prop):" I have aready changed the 50th Vector in "PointsList". But the data printed is the original data in 50th Vector in "PointsList"( The original data in 50th Vector is Vector(0,50,20)). That means the code "theLine.PointsList[50].x=111" is "invalid".
My questions are:
1. Why the code "theLine.PointsList[50].x=111" is "invalid"? How to coding to let the change of 50th Vector effect?
2. The code I get the model is "theLine = FreeCAD.ActiveDocument.getObject("ModelConductor_XXX")". I juest can get the model by the model name. This method is very rustic. In the function " def onChanged(self, vp, prop):" have some para such as "self", How to get the model by para "self" ? I tested the code "self.XXXPropertyName" and "self.obj.XXXPropertyName" , can not work.Can give some code sample to get the model in function " def onChanged(self, vp, prop):" ?
Need suggestion, Thanks a lot.