Update MoveFaceFeature Dimension

Update MoveFaceFeature Dimension

chaines59GWR
Contributor Contributor
155 Views
5 Replies
Message 1 of 6

Update MoveFaceFeature Dimension

chaines59GWR
Contributor
Contributor

Good morning everyone,

 

I have found out how to place a move face feature object, although it is often glitchy. I am looking for a way to change how much the face is moved after a feature is already placed. It looks like I'm supposed to copy the definition of the feature, update it, and then set the feature to have that definition. This is however not working.

 

Does anyone know how I would do this?

 

Sub Main
	
	'MUST BE RUN IN AN ASSEMBLY WITH COMPONENTS 
	
	Dim oFaces As New List(Of FaceProxy) 'CREATE LIST OF FACEPROXIES TO EDIT MOVEFACEFEATURES

	For i = 1 To 2
		oFaces.Add(ThisApplication.CommandManager.Pick(kPartFacePlanarFilter, "Select End Face" & i))
	Next

	For Each oFaceProxy As FaceProxy In oFaces
		
		Dim oFrame As PartComponentDefinition = oFaceProxy.ContainingOccurrence.Definition
		Dim oFace As Face = oFaceProxy.NativeObject
		
		If oFace.CreatedByFeature IsNot Nothing 'IF FACE IS THE RESULT OF A MOVEFACEFEATURE
			If oFace.CreatedByFeature.Type = ObjectTypeEnum.kMoveFaceFeatureObject
				
				Dim oMoveFeat As MoveFaceFeature = oFace.CreatedByFeature
				Dim oFaceDef As MoveFaceDefinition = oMoveFeat.Definition
				oFaceDef.SetDirectionAndDistanceMoveType(5, oFace, True)
				'TRY TO UPDATE OFFSET
				
				Continue For
				
			End If
			
		End If
		
		'IF NO MOVEFACEFEATURE DETECTED, CREATE ONE (THIS WORKS)
		
		Dim oCollect As FaceCollection = ThisApplication.TransientObjects.CreateFaceCollection : oCollect.Add(oFace)

		Dim oMoveDef As MoveFaceDefinition = oFrame.Features.MoveFaceFeatures.CreateDefinition(oCollect)
		oMoveDef.SetDirectionAndDistanceMoveType(10, oCollect(1), True)

		oFrame.Features.MoveFaceFeatures.Add(oMoveDef)

	Next

End Sub
0 Likes
156 Views
5 Replies
Replies (5)
Message 2 of 6

WCrihfield
Mentor
Mentor

Hi @chaines59GWR.  After a quick glance at your comments and the code, it sounds like you described the process one way (get def, edit def, set def back), but then your code is not doing what you described (just getting def, then editing it, but not setting it back).  I copied 3 lines of your code from above, then added a fourth line in there to do the third step (setting the copied & edited definition back as the definition of that feature).

Dim oMoveFeat As MoveFaceFeature = oFace.CreatedByFeature
Dim oFaceDef As MoveFaceDefinition = oMoveFeat.Definition
oFaceDef.SetDirectionAndDistanceMoveType(5, oFace, True)
oMoveFeat.Definition = oFaceDef

 Since the MoveFaceFeature.Definition property is Read/Write, that tells us that we can set a new/different MoveFaceDefinition as the value of that property.  See if that small edit makes it work.

PS.  You may need to update the model after making those types of changes.  You can include one or more lines of code to force the update to the 'referenced' model document, then also the active assembly.  Move Face feature have always seemed a bit buggy even when using them manually, so it is no surprise that they may be a bit buggy interacting with them by code also.  I have had them crash Inventor by simply trying to add/change a face in one of those features in an assembly manually.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 6

chaines59GWR
Contributor
Contributor

It doesn't work unfortunately, and neither does using the .Copy after the definition. I tried to change the "direction" object to many things, but none of them seem to work. The error comes up when trying to set the definition. 

Dim oMoveFeat As MoveFaceFeature = oFace.CreatedByFeature
Dim oFaceDef As MoveFaceDefinition = oMoveFeat.Definition.Copy
oFaceDef.SetDirectionAndDistanceMoveType(5, oFrame.WorkAxes(2), True)
oMoveFeat.Definition = oFaceDef 

 Id like to avoid outright deleting it and replacing it as then I have to refind the faces as the reference is completely destroyed when a MoveFaceFeature is added or removed. 

0 Likes
Message 4 of 6

WCrihfield
Mentor
Mentor

The really odd thing here is that the 'Move Face' feature only appears to be available within the Assembly environment.  When I have part open directly on my screen, that feature is nowhere to be found.  We have the similar 'Thicken / Offset', the 'Direct' feature, the 'Delete Face', and 'Move Bodies', but not move face.  So, I am not sure why it is allowing you to add that type of feature to a part, even when creating it new, instead of editing an existing feature.  Seems like you should be getting that existing feature from within the definition of the assembly, instead of from within the definition of the part.  If you are getting error messages as feedback, do the error messages say what line of code the error is originating from?  The 'More Info' tab of the error message will usually indicate which part of which line of code it is running into an issue.

If the part is within a sub assembly, and you are using the 'Pick' function, you could be selecting a top level proxy, then when you use that proxy's NativeObject property, you could be getting the proxy that is in the context of the sub assembly, then when you get the 'CreatedByFeature', that feature could be a move face feature within that sub assembly, instead of within a part.  Just one thought, because I know proxies are context specific (component definition & 3D coordinate space specific), and there can be multiple levels of them between the true original and what we access in the context of the highest level assembly.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 6

cidhelp
Advocate
Advocate

Hello @chaines59GWR,

 

if your MoveFaceDefinition has MoveFaceType = MoveFaceTypeEnum.kDirectionAndDistanceMoveType then you can get the Distance-Parameter and change its value.

I have increased this parameter in an iLogic-sample 1 cm:

Dim oPart As PartDocument=ThisDoc.Document
Dim MoveFaceFeature As MoveFaceFeature = oPart.ComponentDefinition.Features.MoveFaceFeatures(1)
If MoveFaceFeature.Definition.MoveFaceType = MoveFaceTypeEnum.kDirectionAndDistanceMoveType Then
	Dim oParam As Parameter = MoveFaceFeature.Definition.MoveFaceTypeDefinition.Distance
	oParam.Value= oParam.Value + 1
Else
	Logger.Info("wrong MoveFaceType detected")
End If

iLogicVb.UpdateWhenDone = True

 

Message 6 of 6

WCrihfield
Mentor
Mentor

Good point @cidhelp.  The MoveFaceDefinition.MoveFaceTypeDefinition property says it just returns a generic 'Object' Type value, but when we know what actual Type it will return, we can create a variable of that expected Type, then set the value of that property as the value of that variable.  In this case it would be a DirectionAndDistanceMoveDefinition Type object.  The online help page for that object type does not indicate any way to 'create' a new object of this type, or how to get to an object of this type, so some 'snooping around' appears to be required here to find it.  A similar situation for 'work features' which also have very specific definition sub types, depending on what type of feature it is, and how it gets created/defined.  The other day I thought about going the MoveFaceFeature.FeatureDimensions or the MoveFaceFeature.Parameters direction, but had too many other things going on to dig into it much further at that time.

Edit:  Just for added references, the other types of definition objects for move face type features are FreeMoveDefinition and PlanarMoveDefinition.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes