首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >从Python运行SolidWorks宏

从Python运行SolidWorks宏
EN

Stack Overflow用户
提问于 2022-02-09 02:28:08
回答 1查看 485关注 0票数 -1

我在Python上编写了一个txt文件,其中包含控制点的坐标,然后由SolidWorks读取。

我在SolidWorks上写了一个宏来保存新修改的STL文件。

代码语言:javascript
运行
复制
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?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-02-11 22:32:33

如果有人遇到相同的问题,请进行更新:不应将\m包括在括号中。因此,我的例子是:os.popen(‘C:/User/Public/Desktop/Program/SOLIDWORKS/SOLIDWORKS/..exe“\m”到宏的路径“’)。然而,这只是打开宏,而没有不幸地运行它。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71043299

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档