永发信息网

vbs可以控制solidworks生成x_t文件吗,怎么编程??

答案:1  悬赏:30  手机版
解决时间 2021-03-24 22:24
  • 提问者网友:遮云壑
  • 2021-03-24 03:48
vbs可以控制solidworks生成x_t文件吗,怎么编程??
最佳答案
  • 五星知识达人网友:鸽屿
  • 2021-03-24 05:08
完全可以的
longstatus = Part.SaveAs3(”FileName.x_t“, 0, 0)

我以前写的,与CAD先配名称,没问题转对应的X_T文件

Set AcadApp = GetObject(, "AutoCad.Application")Set SwApp = GetObject(, "SldWorks.Application")
SwApp.Visible (True)
CADPath = AcadApp.ActiveDocument.PathCADPath = Replace(CADPath, "\To Customer", "") '对应的CAD路径
MyPath = AcadApp.ActiveDocument.PathMyPath = MyPath & "\" & Replace(AcadApp.ActiveDocument.Name, ".dwg", ".x_t")
If Dir(MyPath) <> "" Then If MsgBox("检测到文件目录下有图档的STEP文件存在,是否重新生成STEP文件!", vbYesNo, "图形不对应") = vbNo Then
GoTo Err:
End If
End If

OpSW:
SwPath = SwApp.ActiveDoc.GetPathName '当前SW的路径'swApp.CloseDoc "TOP - Model"
If Err.Number <> 0 Then '如果SW没有打开文件
If Dir(CADPath + "\TOP.SLDASM") <> "" Then '找到文件并打开 Set Part = SwApp.OpenDoc6(CADPath + "\TOP.SLDASM", 2, 0, "", longstatus, longwarnings)
SwApp.ActivateDoc2 "\TOP.SLDASM", False, longstatus
Set Part = SwApp.ActiveDoc
SwPath = SwApp.ActiveDoc.GetPathName
SwPath = Replace(SwPath, "\TOP.SLDASM", "")
Else
MsgBox "没有找到文件的3D,程序提前结束!", vbExclamation, "未找到文件"
GoTo Err
End If

Else '如果SW文件已打开存在
SwPath = Replace(SwPath, "\TOP.SLDASM", "")
If CADPath <> SwPath Then '如果发现所打开的2D,3D路径不对应 '同意则重新开图,不同意程序结束
If MsgBox("开起的3D与2D图档路径不对应,是否关闭3D后重新打开!", vbYesNo, "图形不对应") = vbYes Then

SwApp.CloseDoc "TOP.SLDASM" GoTo OpSW
Else
GoTo Err
End If
End If

End If
MyPath = AcadApp.ActiveDocument.Path
MyPath = MyPath & "\" & Replace(AcadApp.ActiveDocument.Name, ".dwg", ".x_t")

If Dir(MyPath) <> "" Then Kill MyPath
SwApp.ActivateDoc2 "\TOP.SLDASM", False, longstatus Set Part = SwApp.ActiveDoc
SwPath = SwApp.ActiveDoc.GetPathName
SwPath = Replace(SwPath, "\TOP.SLDASM", "")

longstatus = Part.SaveAs3(MyPath, 0, 0)
boolstatus = Part.Extension.SketchBoxSelect("0.000000", "0.000000", "0.000000", "0.000000", "0.000000", "0.000000")
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯