Pointer callout for SelectById2

随声附和 提交于 2019-12-07 15:39:32

问题


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)

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

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

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

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.

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

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?


回答1:


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

swModel.FirstFeature

then you ask for the name:

swFeat.Name = "Sketch1"

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

swFeat = swFeat.GetNextFeature


来源:https://stackoverflow.com/questions/19454804/pointer-callout-for-selectbyid2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!