GetLastFeatureAdded

Hello

I can't use the GetLastFeatureAdded method . 

Here is my code that I use to insert a cavity function in an edited component in an assembly! 

boolstatus = swModel.Extension.SelectByID2("" & Name & "@Simulateur", "COMPONENT", 0, 0, 0, False, 0, Nothing, 0) 'Selecting the component I want the thumbprint for
swAssy.InsertCavity4 0.4, 0.4, 0.4, True, 1, -1 'Creating the fingerprint function. 

Then I want to rename this function fingerprint. Because for the future, I want to be sure of the name of the position. Don't take the risk that the imprint will be called a hit "Imprint1" and then "Imprint 3" etc etc. 
So I use the method: GetLastFeatureAdded and then rename the function.

I have declared the following variables: 

Dim swFeat As SldWorks.Feature

Dim swModExt As SldWorks.ModelDocExtension

Then I run the method: 

set swFeat = swModExt.GetLastFeatureAdded

And it tells me that the object variable is not declared. I don't really understand where my mistake or my oversight is. 

Thank you for your advice:)

 

Hello

It's hard to answer like that without the code in front of you.

I suspect however that your variable "swModExt" is not initialized and is therefore empty.

Kind regards

2 Likes

Hello

I think of the same thing as d.roger. See to add Set swModExt = swModel.Extension before Set swFeat

The simplest way to do this is to define it after a line that must be of the type Set swModel = swApp.ActiveDoc and use it from boolstatus = swModExt.SelectbyID2.....

Hello 

My apologies for the delay. 

My swModExt variable is well initialized (I didn't write all the code). I continue to look in any case. Thank you! 

Hello

This is precisely where the complete code is interesting because without it you can make too many assumptions.

- Your variable "swModExt" is well initialized, yes but in relation to what? Your part edited in the assembly or your head assembly? the call to the "ModelDoc2" is not at all the same depending on the level of the component you want to access.

- Depending on how you access your part of your assembly, we can also wonder if your parts are all in solved mode? And if not, is the error handling done (if not "Runtime error 91: object variable or block variable with not defined")?

...

Kind regards

2 Likes