Find specific property in drawing sheet format and change the content

Use this space to ask how to do whatever you're trying to use SolidWorks to do.
User avatar
gt.adan
Posts: 6
Joined: Fri Nov 03, 2023 4:26 am
Answers: 0
Location: Taiwan
x 3

Find specific property in drawing sheet format and change the content

Unread post 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.
by gupta9665 » Tue Nov 07, 2023 3:21 am Go to full post
User avatar
gt.adan
Posts: 6
Joined: Fri Nov 03, 2023 4:26 am
Answers: 0
Location: Taiwan
x 3

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

Unread post 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~
User avatar
josh
Posts: 253
Joined: Thu Mar 11, 2021 1:05 pm
Answers: 11
x 19
x 444

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

Unread post by josh »

OK... You have asked if it is possible... Yes, it's possible.

Are you actually asking someone to do it for you?
User avatar
AlexLachance
Posts: 1994
Joined: Thu Mar 11, 2021 8:14 am
Answers: 17
Location: Quebec
x 2157
x 1847

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

Unread post 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?
User avatar
josh
Posts: 253
Joined: Thu Mar 11, 2021 1:05 pm
Answers: 11
x 19
x 444

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

Unread post 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.
User avatar
DanPihlaja
Posts: 747
Joined: Thu Mar 11, 2021 9:33 am
Answers: 24
Location: Traverse City, MI
x 738
x 893

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

Unread post 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.
-Dan Pihlaja
Solidworks 2022 SP4

2 Corinthians 13:14
User avatar
gt.adan
Posts: 6
Joined: Fri Nov 03, 2023 4:26 am
Answers: 0
Location: Taiwan
x 3

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

Unread post 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.
User avatar
gt.adan
Posts: 6
Joined: Fri Nov 03, 2023 4:26 am
Answers: 0
Location: Taiwan
x 3

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

Unread post 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
User avatar
gupta9665
Posts: 359
Joined: Thu Mar 11, 2021 10:20 am
Answers: 20
Location: India
x 383
x 414

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

Unread post by gupta9665 »

Deepak Gupta
SOLIDWORKS Consultant/Blogger
User avatar
gt.adan
Posts: 6
Joined: Fri Nov 03, 2023 4:26 am
Answers: 0
Location: Taiwan
x 3

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

Unread post 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.
User avatar
gt.adan
Posts: 6
Joined: Fri Nov 03, 2023 4:26 am
Answers: 0
Location: Taiwan
x 3

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

Unread post 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
Post Reply