Rename Work Planes

Rename Work Planes

kv5053545
Advocate Advocate
2,518 Views
7 Replies
Message 1 of 8

Rename Work Planes

kv5053545
Advocate
Advocate

Hello, I am trying to rename the work planes that are inside a Rectangular Pattern that I created from a work plane, but I do not know if it is possible to access the Work Plane that are inside that Rectangular Pattern, so far, I have only been able to access the names of the Rectangular Pattern that exist in my .ipt

 

 

 

For Each oFeature As PartFeature In ThisApplication.ActiveDocument.ComponentDefinition.Features
   
    If TypeOf oFeature Is RectangularPatternFeature Then
        
        Dim oRectPattern As RectangularPatternFeature
        oRectPattern = oFeature
       
	 Dim Pattern As String = oRectPattern.Name
	 If Pattern.Contains("WP_Lock1Pattern") Or   Pattern.Contains("WP_LockWidthPattern")Then
		  MessageBox.Show(Pattern)
	 End If 
    End If
Next

 

this is how the pattern looks like from the model:

 

kv5053545_0-1721061786479.png

 

 

 

0 Likes
Accepted solutions (1)
2,519 Views
7 Replies
Replies (7)
Message 2 of 8

WCrihfield
Mentor
Mentor

Hi @kv5053545.  Have you already tried just accessing those WorkPlanes through the main WorkPlanes property of PartComponentDefinition?  It might be easier that way...unless you plan on renaming them in a way that is associated with their position within the pattern maybe.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 8

kv5053545
Advocate
Advocate
I have tried but it does not let me access the work plane inside the pattern 😞
0 Likes
Message 4 of 8

WCrihfield
Mentor
Mentor
Accepted solution

Here is a traditional route to rename only the WorkPlanes that were created by a rectangular pattern of WorkPlanes in a part.  It does not rename the original 'input' WorkPlane, but that could be added too, if needed.  However, since patterns can be nested inside other patterns, we may sometimes need to use a recursive Sub routine to navigate multiple possible levels of patterns.  This relatively simple example below will only work for a simple, single level pattern.

Dim oPDoc As PartDocument = ThisDoc.Document
Dim oPDef As PartComponentDefinition = oPDoc.ComponentDefinition
Dim oWorkPlanes As WorkPlanes = oPDef.WorkPlanes
Dim oRectPatterns As RectangularPatternFeatures
oRectPatterns = oPDef.Features.RectangularPatternFeatures
If oRectPatterns.Count > 0 Then
	For Each oRPatt As RectangularPatternFeature In oRectPatterns
		If oRPatt.Suppressed Then Continue For
		If oRPatt.Definition.PatternOfBody Then Continue For
		'the initial 'input' features that are being copied by the pattern
		Dim oParentFeats As ObjectCollection = oRPatt.Definition.ParentFeatures
		Dim sPattName As String = oRPatt.Name
		If sPattName.Contains(":") Then sPattName = sPattName.Split(":").First
		Dim oElements As FeaturePatternElements = oRPatt.PatternElements
		If oElements.Count > 0 Then
			For Each oElement As FeaturePatternElement In oElements
				If oElement.Suppressed Then Continue For
				'the actual features that have been created by the pattern
				Dim oResultFeats As ObjectsEnumerator = oElement.ResultFeatures
				If oResultFeats IsNot Nothing AndAlso oResultFeats.Count > 0 Then
					For Each oResultFeat In oResultFeats
						If TypeOf oResultFeat Is WorkPlane Then
							Dim oWPlane As WorkPlane = oResultFeat
							oWPlane.Name = sPattName & " WorkPane " & oElement.Index
						End If
					Next oResultFeat
				End If
			Next oElement
		End If
	Next oRPatt
End If

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)

Message 5 of 8

Curtis_W
Consultant
Consultant

It looks like WCrihfield beat me to it, but here is my version.

 

I was trying to find the work plane that was being patterned ( Work Plane1  in my case) and rename it too, but I could not figure out how to do that???

 

edit: apparently ParentFeatures was what I was looking for

 

Dim oDoc As PartDocument = ThisDoc.Document
Dim oRectPattern As RectangularPatternFeature = Feature.InventorFeature("Rectangular Pattern1")

oFeature = oRectPattern.Definition.ParentFeatures.Item(1) 
If oFeature.IsCoordinateSystemElement = False Then oFeature.name = "WP_1"

For i = 2 To oRectPattern.PatternElements.Count
	oFeat = oRectPattern.PatternElements.Item(i).ResultFeatures.Item(1)
	If TypeName(oFeat) = "WorkPlane" Then
		oFeat.name = "WP_" & i
	End If
Next

 

EESignature

Message 6 of 8

m_andrzejuk3FA7M
Community Visitor
Community Visitor

Thank you for this rule. How can I change it to rename planes in all parts and subassemblies in an assembly?

0 Likes
Message 7 of 8

WCrihfield
Mentor
Mentor

Hi @m_andrzejuk3FA7M.  Your request sound pretty different from the earlier requests in this forum topic, so I am posting a pretty different code example for accomplishing it.  You also did not provide much information or details about this task, so I can only assume that what names are used and how those names are formatted does not matter.  You also did not mention any patterns, so this code example does not even attempt to target those separately.

 

The example code below can be ran from either a part or assembly, and will not only work directly on that main document, but also on all documents being referenced by that main document, at all levels of depth.  This code does avoid errors pretty well, but while doing so, does not provide any feedback about when it encounters any of those issues, or any explanation about why there was an issue.  It could be expanded and developed further to add more checks,  more feedback, and/or more functionality.  Some referenced documents it encounters along the way may be seen as ReadOnly, and when that is the case, it will not be able to make any changes to those.  Some of the ones that may be seen that way are content center members, files located in library directories, iPart/iAssembly members, and ModelState members.  The 'base name' for the new name of each WorkPlane can be changed on Line 21 & Line 26.

Sub Main
	Dim oDoc As Inventor.Document = ThisDoc.Document
	RenameAllWorkPlanes(oDoc)
	For Each oRefDoc As Inventor.Document In oDoc.AllReferencedDocuments
		RenameAllWorkPlanes(oRefDoc)
	Next oRefDoc
	oDoc.Update2(True)
	'oDoc.Save2(True)
End Sub

Sub RenameAllWorkPlanes(oDoc As Inventor.Document)
	If (oDoc Is Nothing) OrElse (Not oDoc.IsModifiable) OrElse
		((Not TypeOf oDoc Is PartDocument) AndAlso
		(Not TypeOf oDoc Is PartDocument)) Then
		Return
	End If
	If oDoc.RequiresUpdate Then oDoc.Update2(True)
	Dim oWPs As WorkPlanes = Nothing
	Try : oWPs = oDoc.ComponentDefinition.WorkPlanes : Catch : End Try
	If oWPs Is Nothing Then Return
	Dim sBaseName As String = "WP"
	Dim iNum1 As Integer = 0 : Dim iNum2 As Integer = 0
	For Each oWP As WorkPlane In oWPs
		If oWP.IsCoordinateSystemElement Then
			iNum1 += 1
			Try : oWP.Name = "Origin" & sBaseName & iNum1.ToString : Catch : End Try
		Else
			iNum2 += 1
			Try : oWP.Name = sBaseName & iNum2.ToString : Catch : End Try
		End If
	Next oWP
	If oDoc.RequiresUpdate Then oDoc.Update2(True)
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 8 of 8

s80463
Community Visitor
Community Visitor

Thank you, it works great, but it rename only planes of parts without assemblies and subassemblies. What can I do to change it?

0 Likes