Moving Text to No Plot layer on all sheets

Moving Text to No Plot layer on all sheets

mslosar
Advisor Advisor
406 Views
2 Replies
Message 1 of 3

Moving Text to No Plot layer on all sheets

mslosar
Advisor
Advisor

What am i doing wrong here? I'm collecting the entities i want to move to a new layer on a sheet, and before moving to the next sheet, i'm executing the layer change. However, no matter where i put the statement i fails due to moving to sheet 2 in a mutlisheet setup.

 

We have an automation app we're running that we're sticking some noted text for the designer. We don't want it to print, so we put it on a no plot layer. However, i can't get it to move to the new layer in a multisheet setup.  With one sheet, i can send it with oGeneralNote.Layer = TargetLayer. But that fails on sheet 2 in a multisheet setup for some reason. What am I missing here?

 

Thanks

Dim odoc As DrawingDocument = ThisApplication.ActiveDocument

Dim oSheet As Sheet

'create blank collection
Dim objColl As ObjectCollection
objColl = ThisApplication.TransientObjects.CreateObjectCollection()
	
Dim TargetLayer As Layer
TargetLayer = ThisDrawing.Document.StylesManager.Layers("NoPlot")

For Each oSheet In odoc.Sheets	
	oSheet.Activate
	For Each oGeneralNote In oSheet.DrawingNotes.GeneralNotes
		
		If oGeneralNote.Text.Contains("#DESIGNER NOTE#") Then
			MessageBox.Show("Found one", "Title")
			objColl.Add(oGeneralNote)
			'oSheet.ChangeLayer(objColl, TargetLayer)
			'oGeneralNote.Layer = TargetLayer
		End If	
		
	Next		
	oSheet.ChangeLayer(objColl, TargetLayer)
Next
0 Likes
Accepted solutions (1)
407 Views
2 Replies
Replies (2)
Message 2 of 3

WCrihfield
Mentor
Mentor
Accepted solution

Since your object collection is being created above your loops, it is getting all objects from all sheets added to it, because it isn't being cleared for each sheet.  If you created it within the loop of the sheets it would work better.  Or if you cleared at the start of each sheet's loop, or right after using ChangeLayer at the end of each loop, it would also work better.

Try it this way:

Dim odoc As DrawingDocument = ThisApplication.ActiveDocument
Dim TargetLayer As Layer = odoc.StylesManager.Layers("NoPlot")
For Each oSheet As Sheet In odoc.Sheets	
	oSheet.Activate
	Dim objColl As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection()
	For Each oGeneralNote As GeneralNote In oSheet.DrawingNotes.GeneralNotes
		If oGeneralNote.Text.Contains("#DESIGNER NOTE#") Then
			MessageBox.Show("Found one", "Title")
			objColl.Add(oGeneralNote)
		End If	
	Next		
	oSheet.ChangeLayer(objColl, TargetLayer)
	objColl.Clear
Next

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

If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 3

mslosar
Advisor
Advisor

Thank you for that. Been spending all my time in a completely other environment and haven't dealt much with collections. That seems to do it.

 

Thanks for the correction and the explanation!

0 Likes