Page 1 of 1

Find specific property in drawing sheet format and change the content

Posted: Fri Nov 03, 2023 4:47 am
by gt.adan
Hi everyone. My question is as follow :
There is a linking property named $PRP:"SW-File Name" in EVERY drawing sheet format. Is it possible to get it and change the content to certain words or to custom property like $PRPSHEET:"Customer Spec" via VBA? Any idea is welcomed.

Re: Find specified property in drawing sheet format and change the content

Posted: Sun Nov 05, 2023 7:59 pm
by gt.adan
Not one reply!? It's a little bit frustrated... :( Maybe I didn't express my problem clearly.
This work can be accomplished by batch replacing sheet formats. But I cannot do it because there are some properties in the drawings linked to specific view name. Further more, there are some drawings contain more than 2 pages.
Once again, any help is appreciated~

Re: Find specified property in drawing sheet format and change the content

Posted: Mon Nov 06, 2023 11:00 am
by josh
OK... You have asked if it is possible... Yes, it's possible.

Are you actually asking someone to do it for you?

Re: Find specified property in drawing sheet format and change the content

Posted: Mon Nov 06, 2023 3:25 pm
by AlexLachance
It's not very clear to me what you are trying to achieve, so that could be a reason why people are hesitant to answer.

Why would you want a manual entry rather then use the existing ones? Do you understand the entries and what they link?

Re: Find specified property in drawing sheet format and change the content

Posted: Mon Nov 06, 2023 3:56 pm
by josh
I believe he's looking for a "Find-Replace" in annotations, except that it works for notes linked to properties rather than just looking at the displayed text.

Re: Find specified property in drawing sheet format and change the content

Posted: Mon Nov 06, 2023 4:50 pm
by DanPihlaja
josh wrote: Mon Nov 06, 2023 3:56 pm I believe he's looking for a "Find-Replace" in annotations, except that it works for notes linked to properties rather than just looking at the displayed text.
Artemis' #TASK would do this, I think. I don't think that it works any more though.

Re: Find specified property in drawing sheet format and change the content

Posted: Tue Nov 07, 2023 1:16 am
by gt.adan
Hello Alex. Please forgive my bad English. I've been using SW for more than 10 years, so yes, I know the entries and what they link.
Actually, what I want is to replace "$PRP:"SW-Folder Name"" with "$PRPSHEET:"Customer Spec"" in the sheet format, not the "File Name" I mentioned before.
Older drawings show the full path name in the customer specification field, which is the link "$PRP:"SW-Folder Name"", but the displayed text is too long. Now I create a new template, use simple code to extract the spec information I need, and write it into the custom property, which is the link "$PRPSHEET:"Customer Spec"".
The new template works well and has been running for a while, but I have to go back and work on the old projects.
There are so many drawings to process, but they are just repetitive actions. I know this job can be done using VBA code batch processing, but I'm still very new to programming, so came here to ask for help.

Re: Find specified property in drawing sheet format and change the content

Posted: Tue Nov 07, 2023 1:37 am
by gt.adan
josh wrote: Mon Nov 06, 2023 11:00 am OK... You have asked if it is possible... Yes, it's possible.

Are you actually asking someone to do it for you?
Hi, Josh, thanks for the reply, but I'm not here to ask someone to do it for me.
In fact, I did some research. I used the information on the Internet and my very shallow knowledge of VBA to write some code, but I always failed. That's why I'm here for help. What I need to replace is the link in the sheet format rather than the drawing, but the following code always shows that it cannot be defined. I am still working on it.
2023110702.png

Re: Find specified property in drawing sheet format and change the content

Posted: Tue Nov 07, 2023 3:21 am
by gupta9665

Re: Find specified property in drawing sheet format and change the content

Posted: Tue Nov 07, 2023 7:41 am
by gt.adan
Hi, Deepak. Thank you for the three links you provided, I will read them carefully later. I believe I can get helpful information from them.

Re: Find specified property in drawing sheet format and change the content

Posted: Wed Nov 08, 2023 12:05 am
by gt.adan
@gupta9665
I modify the code you provided in the 3rd link, and it works perfect!
I've always thought that the code for replacing properties in a sheet was different than the code for replacing properties in a sheet format.
Thank you again~ Here is the code
==============================================================================================
Option Explicit

Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc
Dim swDraw As SldWorks.DrawingDoc
Dim swView As SldWorks.View
Dim swNote As SldWorks.Note
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swDraw = swModel
Set swView = swDraw.GetFirstView

While Not swView Is Nothing
Set swNote = swView.GetFirstNote
While Not swNote Is Nothing
If swNote.PropertyLinkedText Like "$PRP:""SW-Folder Name(Folder Name)""" Then
Debug.Print "Replacing " & swNote.GetText & " (" & swNote.PropertyLinkedText & ")"
swNote.PropertyLinkedText = "$PRPSHEET:""Customer Spec"""
End If
Set swNote = swNote.GetNext
Wend
Set swView = swView.GetNextView
Wend
End Sub