SelectById2的指针标注 [英] Pointer callout for SelectById2

查看:225
本文介绍了SelectById2的指针标注的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试移植我在VBA中编写的一些代码,以将Solidworks控制在Python中.专门自动化草图编辑.我在Python中使用Solidworks SelectById2时遇到问题.在VBA中,以下代码可以正常工作:

I'm trying to port over some code I wrote in VBA to control Solidworks in to Python. Specifically automating sketch edits. I am having problems using Solidworks SelectById2 in Python. In VBA the following code works fine:

Part.Extension.SelectByID2("Sketch1", "SKETCH", 0, 0, 0, False, 0, Nothing, 0)

我遇到的问题是用一些等效的Python替换VBA的"Nothing"值.

The problem I am having is replacing VBA's "Nothing" value with some Python equivalent.

SelectByID2在Solidworks API文档中正在寻找的东西:

From the Solidworks API Docs, what SelectByID2 is looking for is:

SelectByID2(Name, Type, X, Y, Z, Append, Mark, Callout, SelectOption)

其中标注是指向相关标注的指针.我宁愿不要创建一个指针,因为它与我无关,而且我在VBA中看到它是不必要的.

Where Callout is a pointer to the associated callout. I would prefer to not to create a pointer since it is not relevant to me and I have seen in VBA that it is not necessary.

我尝试使用Python的None,pythoncom.Missing,pythoncom.Empty,",",0 ...都无济于事.所有这些给了我一个TypeError.

I have tried using Python's None, pythoncom.Missing, pythoncom.Empty, "", " ", 0 ... all to no avail. All of these give me a TypeError.

这是我相关的Python代码:

Here is my relevant Python code:

import win32com.client
import pythoncom

pythoncom.CoInitializeEx(pythoncom.COINIT_APARTMENTTHREADED)

sldworks = win32com.client.gencache.EnsureModule('{83A33D31-27C5-11CE-BFD4-00400513BB57}', 0x0, 20, 0) # Solidworks OLE Automation 1.0 Type Library
swconst = win32com.client.gencache.EnsureModule('{4687F359-55D0-4CD3-B6CF-2EB42C11F989}', 0x0, 20, 0)  # Solidworks 2012 Constant Type Library

sw = sldworks.SldWorks()
sw.Visible = 1
model_path = "Y:\\Templates\\Solidworks\\test.SLDPRT"
doc, errors, warnings = sw.OpenDoc6(model_path, swconst.constants.swDocPART, swconst.constants.swOpenDocOptions_Silent, "", pythoncom.Missing, pythoncom.Missing)
sw.ActivateDoc2(model_path, False,pythoncom.Missing)
Part = sw.ActiveDoc  

try:
    Part.Extension.SelectByID2("Sketch1", "SKETCH", 0, 0, 0, False, 0, ffff, 0)
except Exception, value:        
    print "Exception occured, value = ", value 

关于如何解决这个问题的任何建议?

Any suggestions on how to go about figuring this out?

推荐答案

我知道它不能解决您的问题,但是也许您可以使用以下解决方法:

i know its not solving your problem, but maybe you can use a workaround with:

swModel.FirstFeature

然后您要求输入名称:

swFeat.Name = "Sketch1"

如果它不是您要查找的草图,请继续进行下一个草图:

if its not the sketch you are looking for, head on for the next one:

swFeat = swFeat.GetNextFeature

这篇关于SelectById2的指针标注的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆