乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 35|回复: 1

[综合讨论] SW Macro - How to reference $P

[复制链接]

1

主题

2

帖子

1

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-8 21:40:50 | 显示全部楼层 |阅读模式
Hello All,
 
I am writing this macro to help handle our drawing releases throughout the company I work for. We have issues with Solidworks assemblies (and the occasional drawing) not being the most stable things in the world so I have "pieced" this together to save clean copies of our work at revision releases in .pdf format (I'm no programmer, last time I used VB was 5 years ago in intro to engineering).
 
Feel free to review and suggest ways to clean up the code but the main reason I am here is I wish to automate the process of pulling the revision letter from the part. Currently I have the code set up to prompt the user to enter the current Revision level (see line in Red). I would like to rewrite this line to pull from our property sheet for the part/assembly that is referenced in the open drawing. Each part we make has a Property sheet we pull info from to fill out the title block on our drawings, this typically requires a $PRPSHEET call in the drawing template to pull the info in automatically. I would really like to know how I can reference this information from my VB code and dimension it to a string variable to be used later in the code.
 
Does anyone know how to execute this?
 
 
  1. Imports SolidWorks.Interop.sldworksImports SolidWorks.Interop.swconstImports System.Runtime.InteropServicesImports SystemImports System.IOPartial Class SolidWorksMacroPublic Sub main()Dim swDoc As ModelDoc2 = NothingDim longstatus As Integer = 0Dim CurrentFilePath As String = ""Dim CurrentFileName As String = ""Dim ParentFilePath As String = ""Dim NewFileName As String = ""Dim ReleaseFilePath As String = ""Dim RevFilePath As String = ""Dim RevFileName As String = ""Dim RevLevelAdd As String = ""Dim RevLevel As String = ""swDoc = CType(swApp.ActiveDoc, ModelDoc2)[color="red"]RevLevel = InputBox("Please enter the new revision level", "Revision Entry", "A", , )[/color]CurrentFilePath = swDoc.GetPathName CurrentFileName = IO.Path.GetFileNameWithoutExtension(CurrentFilePath) ParentFilePath = IO.Path.GetDirectoryName(CurrentFilePath) RevLevelAdd = CurrentFileName & "_Rev " & RevLevel My.Computer.FileSystem.CreateDirectory(ParentFilePath & "\Revision Archive") RevFileName = IO.Path.ChangeExtension(RevLevelAdd, ".pdf") RevFilePath = ParentFilePath & "\Revision Archive" If File.Exists(RevFilePath & RevFileName) Then MsgBox("Revision Level Already Exists - Cannot Overwrite File", MsgBoxStyle.Information) Exit Sub Else longstatus = swDoc.SaveAs3(RevFilePath & RevFileName, 0, 0) MsgBox("Saved Drawing as: " & RevFilePath & RevFileName, MsgBoxStyle.Information) CurrentFilePath = swDoc.GetPathName CurrentFileName = IO.Path.GetFileName(CurrentFilePath) ParentFilePath = IO.Path.GetDirectoryName(CurrentFilePath) My.Computer.FileSystem.CreateDirectory(ParentFilePath & "\Release") NewFileName = IO.Path.ChangeExtension(CurrentFileName, ".pdf") ReleaseFilePath = ParentFilePath & "\Release" longstatus = swDoc.SaveAs3(ReleaseFilePath & NewFileName, 0, 0) MsgBox("Saved Drawing as: " & ReleaseFilePath & NewFileName, MsgBoxStyle.Information) MsgBox("All Done, Have A Nice Day!!", MsgBoxStyle.Information) End IfEnd SubPublic swApp As SldWorksEnd Class
回复

使用道具 举报

1

主题

2

帖子

1

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-8 22:53:05 | 显示全部楼层
I would consider posting this to the api section of the Solidworks forums.
https://forum.solidworks.com/community/solidworks/api
 
I have a little experience with coding, but unfortunately not enough to do what you require.
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-4 01:31 , Processed in 0.489737 second(s), 56 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表