9 Replies Latest reply on Mar 14, 2019 2:26 PM by Michael Corriveau-Cote

# Get Normal of Face in an Assembly

Hi Folks,

I need to get the normal of a selected face in an assemlby.

If i just get the normal of that face it is the normal of the face inseid the part not the normal it has in the assembly.

How can i get the normal of that face how it is in the assembly.

Thanks.

Regards, Carsten

• ###### Re: Get Normal of Face in an Assembly

Hi Carsten,

1) Get the SolidWorks math vector object from your current normal: MathUtility::CreateVector.

2) Get the component of your face (Entity::GetComponent). Or any other method depending on your case.

3) Get the transformation of the component: IComponent2::Transform2

4) Multiple the transformation from #3 to the vector from #1. MathVector::MultiplyTransform.

5) Get the new vector coordinates: MathVector::ArrayData.

• ###### Re: Get Normal of Face in an Assembly

Hi Artem,

i going to try it like You described.

The confusing thing for me is point 4.

Thanks.

Regards, Carsten

• ###### Re: Get Normal of Face in an Assembly

Hi Artem,

I added an assembly an a VBA-Macro.

Open the Test.sldasm und preselect a face before running the macro.

In the second last line there is the vector.

I would say the vector should always contain 0s and 1s and nothing else.

But there are also other values.

Cann you tell m what i am doing wrong?!

Thanks.

Redards, Carsten

• ###### Re: Get Normal of Face in an Assembly

When I run it, it always returns only 1s and 0s.  Except that due to math/rounding errors, sometimes 0 looks like 1.520569961E-16, which is just as good as 0.

• ###### Re: Get Normal of Face in an Assembly

Hi josh,

thanks for the Information.

I going to investigate a little mir in the evening.

regards, Carsten

• ###### Re: Get Normal of Face in an Assembly

Hi Artem and Josh,

I had one more mistake in my code: I dind't use the Face parameters for the createvector (i used 0, 0, 1).

I also didn't saw that there was the "E-16" at the end of the value.

So now i works fine.

Have a nice Weekend.

Greets, Carsten

• ###### Re: Get Normal of Face in an Assembly

I would also recommend taking taking a look at some of the API examples in the help for a template for organizing your code for readability.  It really helps debugging, and helps when others have to come behind you and decipher your code.

• ###### Re: Get Normal of Face in an Assembly

Hi Josh,

i know that the Code style in this example wasn't nice to check.

I just copied those lines together from the api help to check if its the right was or if i was on the wrong way.

Now that i know it is the right way i adapted the Code in a better way to read in my addin project.

Next time i habe a question i will provide Code that will be easier to read.

Thanks, Carsten.

• ###### Re: Get Normal of Face in an Assembly

Artmen!! Always there to save the day! Thank you so much it helped me too!

Very appreciated