API:Get custom prop from referenced model

I have a macro that I use to generate a pdf of an open drawing. My drawing filename is simply the part number. I want to Macro to append a revision to the end of the filename before saving as a pdf. I carry the current rev in a custom propety in the model. I have a note on my sheet format that references this to diplay the rev in the title block.

I can't seem to use part.getcustominfo2 because it looks in the custom property area of the drawing (which is empty)

I do not know how to access the properties of the referenced model like my notes do ($PRPSHEET:REV).

Any ideas how to do this. I know only enough VB to find my way around the help file. I have not gotten anywhere with this. I think I could use Note.GetPropertyLinkedText if I knew how to point to the note.

Any tips would be appreciated.


Reply to
Loading thread data ...

You are in luck I just wrote this a month or 2 ago. It figures out which view is the one used for custom properties on the current sheet then connects to the referenced part (which I believe Deb posted an easier way of getting the referenced part recently, I had used the long way) and gets the Description field (I handled it so that this is not case sensitive) and adds the same field to the drawing. You can easily modify it to get any field you want, I hadn't handled config specific properties, because I almost never use them.

Option Compare Text 'this line needs to be at the top of the module 'so that it compares non-case sensitive

Private Function swDrw_FileSaveNotify(ByVal fileName As String) As Long

Dim ThisSheet As SldWorks.Sheet Dim ThisView As SldWorks.view Dim ThisViewName As String Dim ModelName As String Dim ThisModel As SldWorks.ModelDoc2 Dim Description As String Dim CustomInfoNms() As String Dim Count As Long

Set ThisSheet = swDrw.GetCurrentSheet ThisViewName = ThisSheet.CustomPropertyView Set ThisView = swDrw.GetFirstView

Do While Not ThisView Is Nothing If ThisViewName = ThisView.Name Then Exit Do End If Set ThisView = ThisView.GetNextView Loop

If ThisView Is Nothing Then Set ThisView = swDrw.GetFirstView ModelName = ThisView.GetReferencedModelName While ModelName = "" And Not ThisView Is Nothing Set ThisView = ThisView.GetNextView If ThisView Is Nothing Then Exit Function ModelName = ThisView.GetReferencedModelName Wend If ThisView Is Nothing Then Exit Function End If Set ThisModel = swApp.GetOpenDocumentByName(ModelName)

CustomInfoNms = ThisModel.GetCustomInfoNames2("") Count = 0 Description = "" 'Find the Field labled Description and set that value For Count = 0 To UBound(CustomInfoNms) If CustomInfoNms(Count) = "description" Then Description = ThisModel.GetCustomInfoValue("", CustomInfoNms(Count)) Exit For End If Next

If Description = "" Then Exit Function If Not ActvDoc.GetPathName = fileName Then MsgBox "Caution Active doc is: " & ActvDoc.GetTitle & vbcrlf & "This was not the document you started with!!!!

'the Rest of the lines set the Description field of the drawing to be the same as the 'referenced model

CustomInfoNms = ActvDoc.GetCustomInfoNames2("") Count = 0

For Count = 0 To UBound(CustomInfoNms) If CustomInfoNms(Count) = "description" Then retval = ActvDoc.DeleteCustomInfo2("", CustomInfoNms(Count)) End If Next retval = ActvDoc.AddCustomInfo3("", "Description", 30, Description) End Function


Corey Scheich

Reply to
Corey Scheich

"Corey Scheich" wrote in news:c66lr0$8o5qh$ snipped-for-privacy@ID-200385.news.uni-berlin.de:

Thanks Corey, I'll give it a try. I kind of thought I might have to interrogate the drawing like that but had no idea how to actually accomplish it.


Reply to

I noticed that Corey gave you some code to get the properties of the referenced model, which is great, but if the data you want is already in a note, you can also access that note. You can use the SelectByID function to select a note with its name. The only problem is that I have found no way to see a note's name in SolidWorks other than through the API. So, I wrote an addin that just allows you to view and change the names of notes. Once you know the name (usually you want to save it in a sheet format or some such so it is the same name on all your drawings), it's easy to read and change the note text. Basically you do something like this (forgive me if it's not quite correct - I mostly use C++):

Part.Extension.SelectByID "NoteName@SheetFormatName", "NOTE", 0, 0, 0, False, 0, null Note = Part.SelectionManager.GetSelectedObject5(1) text = Note.GetText

So that's pretty easy, except you may want to add some error checking. I use the SetText method to fill in a lot of notes. We have a spreadsheet set up for our different sheet formats that has the note names in one column and the note text in another. That way it's really easy for the guys to enter all the info quickly. Then they just click a button, and a VB macro fills in all the notes for them. I know you can do some of the same stuff with custom properties, but that's how we do it. If you want a copy of the addin for setting notes, send me an email. Be sure to use my name in the email or it'll get deleted. Zipped, the file is only 25 KB, so it's no problem with email. It does require MFC 7.1 and the visual C++ runtime 7.1 though, which you should be able to get from Microsoft or just search for them. The specific ones are mfc71u.dll and msvcr71.dll.

Jonathan Anderson snipped-for-privacy@jwoperating.com Include my first name in the body or subject of an email to get past my filters.

Reply to
Jonathan Anderson

PolyTech Forum website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.