我在Python上编写了一个txt文件,其中包含控制点的坐标,然后由SolidWorks读取。
我在SolidWorks上写了一个宏来保存新修改的STL文件。
import numpy as np
import os
def GenerateCoordinates(low,high,size):
X=np.random.randint(low,high,size)
Y=np.random.randint(low,high,size)
#Z=np.random.randint(low,high,size)
return X,Y
X=GenerateCoordinates(0,6,7)[0]
Y=GenerateCoordinates(0,4,7)[1]
k=0
sketch_number=1 #Generate coordinates
g=open('Cdd.txt','w')
for i in range(1,len(X)):
g.write('CoordinatesX'+str(i)+'='+str(X[i])+'\n')
g.write('"D'+str(k)+'@Sketch'+str(sketch_number)+'"'+'=CoordinatesX'+str(i)+'\n')
k+=1
g.write('CoordinatesY'+str(i)+'='+str(Y[i])+'\n')
g.write('"D'+str(k)+'@Sketch'+str(sketch_number)+'"'+'=CoordinatesY'+str(i)+'\n')
k+=1
#g.write('CoordinatesZ'+str(k)+'='+str(Z[i])+'\n')
#g.write('D'+str(k)+'@Sketch'+str(sketch_number)+'=CoordinatesZ'+str(k)+'\n')
g.close() #writes coordinates in a txt file then saves the txt file
os.popen('"C:/Users/Public/Desktop/Program Files/SOLIDWORKS Corp/SOLIDWORKS/.exe"') #I want to call the macro that rebuilds the solidworks part with the modified coordinates.
如何从Python运行宏,将新文件导入Python?
发布于 2022-02-11 14:32:33
如果有人遇到相同的问题,请进行更新:不应将\m包括在括号中。因此,我的例子是:os.popen(‘C:/User/Public/Desktop/Program/SOLIDWORKS/SOLIDWORKS/..exe“\m”到宏的路径“’)。然而,这只是打开宏,而没有不幸地运行它。
https://stackoverflow.com/questions/71043299
复制相似问题