Updating idw styles and getting double prompt...would like just one.

Updating idw styles and getting double prompt...would like just one.

steveh5
Advisor Advisor
678 Views
12 Replies
Message 1 of 13

Updating idw styles and getting double prompt...would like just one.

steveh5
Advisor
Advisor

Hello All....

Scripting some iLogic to update idw styles.

I have the logic working but just would like one prompt instead of a prompt for every style that is out of date (at least I think that is what is happening).

 

Here's a link to a video...

https://www.screencast.com/t/IkOqZF3HZj

 

Here's the iLogic...

'This logic runs thru all of Drawings Styles and updates them.

Sub Main()
OpenDoc = ThisDoc.Document
oStyles = OpenDoc.StylesManager.Styles

'Runs thru all Styles and see if they are up to date
For Each oStyle As Style In oStyles
	If Not oStyle.UpToDate Then
		
'		Pop up message asking if you want to update styles
		Dim msg As MsgBoxResult = MessageBox.Show("Update to Current Drawing Styles?", "Styles Update", MessageBoxButtons.YesNoCancel,
		MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2)
		
		If msg = vbYes Then
			oStyle.UpdateFromGlobal
		Else
		End If
	End If
Next
Try
	OpenDoc.Save

Catch
End Try

'Tells user that Styles have been updated.
MessageBox.Show("Drawing Styles have been Updated" & vbCr & oFile)

End Sub

 

Thanks in advance!!!!

Steve Hilvers
Inventor Certified User / Vault Professional Influencer
0 Likes
Accepted solutions (3)
679 Views
12 Replies
Replies (12)
Message 2 of 13

WCrihfield
Mentor
Mentor

Hi @steveh5.  This should do it for you.  I just got rid of the question in the middle of the loop, and the conditional statement, based on the answer to that question.  Then condensed some stuff a bit.

'This logic runs thru all of Drawings Styles and updates them.
Sub Main()
	OpenDoc = ThisDoc.Document
	oStyles = OpenDoc.StylesManager.Styles
	'Runs thru all Styles and see if they are up to date
	For Each oStyle As Style In oStyles
		If Not oStyle.UpToDate Then oStyle.UpdateFromGlobal
	Next
	Try : OpenDoc.Save : 	Catch : End Try
	'Tells user that Styles have been updated.
	MessageBox.Show("Drawing Styles have been Updated" & vbCr & oFile)
End Sub

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 13

steveh5
Advisor
Advisor

@WCrihfield ...

Thanks for the insight....but I would like to be prompted ONCE to update all Styles.

Your suggestion took the question out completely.

 

Thank you,

Steve H. 

Steve Hilvers
Inventor Certified User / Vault Professional Influencer
0 Likes
Message 4 of 13

WCrihfield
Mentor
Mentor

OK, I misunderstood.  I thought the one prompt you were talking about was the one at the end.  Here is a version with a question before the loop, asking if you want to proceed with updating all drawing styles.

 

'This logic runs thru all of Drawings Styles and updates them.
Sub Main()
	OpenDoc = ThisDoc.Document
	oStyles = OpenDoc.StylesManager.Styles
	oAns = MessageBox.Show("Do you want to update all Styles in this drawing?", _
	"Update Drawing Styles", MessageBoxButtons.YesNo, MessageBoxIcon.Question, _
	MessageBoxDefaultButton.Button2)
	If oAns = DialogResult.Yes Then
		'Runs thru all Styles and update them, if needed
		For Each oStyle As Style In oStyles
			If Not oStyle.UpToDate Then oStyle.UpdateFromGlobal
		Next
	End If
	Try : OpenDoc.Save : Catch : End Try
	'Tells user that Styles have been updated.
	MessageBox.Show("Drawing Styles have been Updated" & vbCr & oFile)
End Sub

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 13

steveh5
Advisor
Advisor

@WCrihfield 

Thanks again...there was a bug in your code, so I tweaked a bit. Think there was a problem with Dialog box codde.

It runs now, but it even prompts me to update styles even when they are already up to date.

Anyway to get around that?

 

'This logic runs thru all of Drawings Styles and updates them.
Sub Main()
	OpenDoc = ThisDoc.Document
	oStyles = OpenDoc.StylesManager.Styles
	
	'		Pop up message asking if you want to update styles
		oAns = MessageBox.Show("Update to Current Drawing Styles?", "Styles Update", MessageBoxButtons.YesNoCancel,
		MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2)
	
	
	If oAns = DialogResult.Yes Then
		'Runs thru all Styles and update them, if needed
		For Each oStyle As Style In oStyles
			If Not oStyle.UpToDate Then oStyle.UpdateFromGlobal
		Next
	End If
	Try : OpenDoc.Save : Catch : End Try
	'Tells user that Styles have been updated.
	MessageBox.Show("Drawing Styles have been Updated" & vbCr & oFile)
End Sub

  Best,

Steve H.

Steve Hilvers
Inventor Certified User / Vault Professional Influencer
0 Likes
Message 6 of 13

WCrihfield
Mentor
Mentor
Accepted solution

If we create a Boolean type variable named something like 'RequiresUpdate', set to False initially, then loop all drawing styles before the main question, checking if each is 'UpToDate', and as soon as any one of them returns False, then set the boolean variable to True, then exit the loop.  Then check the value of that boolean.  If False, simply exit the rule, because no update is needed.  But if it is True, then ask the question, then if Yes, run the rest of the rule, as before.  This requires two loops of all styles though, instead of just the one, so it would be less efficient, but would get the job done the way you want.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 7 of 13

steveh5
Advisor
Advisor
Accepted solution

@WCrihfield 

Thanks for the guidance. With your help, I'm really close.

If I run the iLogic manually, does exactly what I need it to do.

But, if I attach it to an Event Trigger so that on Drawings it runs "After Open Document, it errors.

What am I missing?

steveh_0-1668631215820.png

 

'This logic runs thru all of Drawings Styles and updates them.
Sub Main()
	OpenDoc = ThisDoc.Document
	oStyles = OpenDoc.StylesManager.Styles
	
'Sets Update dialog to initially False
Dim RequiresUpdate = False
	
'Runs thru all Styles and switches to RequiresUpdate to True
		For Each oStyle As Style In oStyles
			If Not oStyle.UpToDate Then RequiresUpdate = True
		Next	
	
	
If RequiresUpdate = True Then	
	'		Pop up message asking if you want to update styles
		oAns = MessageBox.Show("Update to Current Drawing Styles?", "Styles Update", MessageBoxButtons.YesNoCancel,
		MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2)
	
	
	If oAns = DialogResult.Yes Then
		'Runs thru all Styles and update them, if needed
		For Each oStyle As Style In oStyles
			If Not oStyle.UpToDate Then oStyle.UpdateFromGlobal
		Next
	End If
'Tells user that Styles have been updated.
'	MessageBox.Show("Drawing Styles have been Updated!" + vbCrLf + vbCrLf + "PLEASE Review all Dimensions and Balloons" & vbCr & oFile)
End If


	Try : OpenDoc.Save : Catch : End Try

If oAns = DialogResult.Yes Then
'Tells user that Styles have been updated.
	MessageBox.Show("Drawing Styles have been Updated!" + vbCrLf + vbCrLf + "PLEASE Review all Dimensions and Balloons" & vbCr & oFile)
End If

End Sub

 

Best,

Steve Hilvers
Inventor Certified User / Vault Professional Influencer
0 Likes
Message 8 of 13

WCrihfield
Mentor
Mentor

Hi @steveh5.  I am not sure.  What does the error message say?  Could you include what both tabs of the error message say when it pops-up?  There is usually a pretty good clue somewhere within the More Info tab, that would tell us what it was trying to do when the error was encountered, which will usually make it easier for us to pinpoint which line of code that is happening at.  Since you said it is working OK when ran manually, that makes me think there may be a timing issue involved.  Maybe the rule is triggered to run too early after the document is opened, and it maybe has not fully loaded all styles related stuff.  Just a thought.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 9 of 13

steveh5
Advisor
Advisor

So, I went and re-did my triggers and now it works without error.  Went thru around 30 idw's and all seems well 😁.

 

Thanks @WCrihfield for the expertise!!!

Steve Hilvers
Inventor Certified User / Vault Professional Influencer
0 Likes
Message 10 of 13

steveh5
Advisor
Advisor

So,  moving this iLogic over to another machine and periodically I get this error on the second machine. I was getting same error on my machine at first too. I can't seem to get it on my machine now. Opening same file as other machine. He gets error I don't.

I'm pretty sure it has something to do with the trigger. I run the logic manually and not thru the trigger, I don't get an error on that second machine. Originally, my machine was acting same way.

Here's the error....

steveh_0-1669044145359.pngsteveh_1-1669044158517.png

Any thoughts?

Best,

Steve H.

Steve Hilvers
Inventor Certified User / Vault Professional Influencer
0 Likes
Message 11 of 13

WCrihfield
Mentor
Mentor

That second error screen indicates that the error happened while it was performing an 'UpdateFromGlobal' method on a Style.  Are your styles/style libraries located locally on each machine, or are they stored centrally, like on a server?  If on a server, then if mapped drives are being used, make sure everyone has the same drive letter for that location, otherwise you may have to eliminate the use of mapped drive letters in your paths, and use the full path back to the server in your paths.  Just one tip I picked up due to similar sounding issues a couple years ago.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 12 of 13

steveh5
Advisor
Advisor

Yes...they are locally, we store in Vault and push down to our C: drive every night.

I was just able to repeat it on my machine again. Same error.

Hmmm????

Steve Hilvers
Inventor Certified User / Vault Professional Influencer
0 Likes
Message 13 of 13

WCrihfield
Mentor
Mentor
Accepted solution

I guess to help avoid this error, you could just replace this:

If Not oStyle.UpToDate Then oStyle.UpdateFromGlobal

...with this:

If Not oStyle.UpToDate Then
	Try : oStyle.UpdateFromGlobal : Catch : End Try
End If

It doesn't explain why the error is happening, but helps you keep moving forward.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes