Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Distance between 2 parallel planes.

Status
Not open for further replies.

sanganaksakha

Mechanical
Apr 24, 2007
16
0
0
IN
How can I get the distance between 2 parallel planes using VBA?
The planes are in a geometrical set in a part.
 
Replies continue below

Recommended for you

Try this:

Code:
Func GetMinimumDistance( Reference  iMeasuredItem) As double  

Compute the minimum distance between the CATIAMeasurable and another. Bodies (openbody, hybridbody..) cannot be measured between. 
Parameters: 
oCoordinates 
The information of the axis system with respect to the product coordinate system: 
oComponents(0) is the X coordinate of the origin of the axis system 
oComponents(1) is the Y coordinate of the origin of the axis system 
oComponents(2) is the Z coordinate of the origin of the axis system 
oComponents(3) is the X coordinate of the first direction of the axis system 
oComponents(4) is the Y coordinate of the first direction of the axis system 
oComponents(5) is the Z coordinate of the first direction of the axis system 
Example: 
     This example retrieves the distance between the reference1 and reference2.
    Dim reference1 As Reference
    Set reference1 = part1.CreateReferenceFromObject(object1)
    Dim reference2 As Reference
    Set reference2 = part1.CreateReferenceFromObject(object1)
    Dim TheSPAWorkbench As Workbench
    Set TheSPAWorkbench = CATIA.ActiveDocument.GetWorkbench ( "SPAWorkbench" )
    Dim TheMeasurable As Measurable
    Set TheMeasurable = TheSPAWorkbench.GetMeasurable(reference1)
    Dim MinimumDistance As double
    MinimumDistance = TheMeasurable.GetMinimumDistance(reference2)

Tiago Figueiredo
Tooling Engineer

Youtube channel:
 
Thank you Tiago,

It works in VBA.

How ever, in VB.net the line

MinimumDistance = TheMeasurable.GetMinimumDistance(reference2)

gives an error

"HRESULT E_FAIL has been returned from a call to a COM component"

Also how can we see properties and methods on CATIA COM components in VB.net?
 
It is already imported. In rest of the program it is working.
I am creating two planes, moving them by some math and then measuring the final distance with them. Only at this line it gets stuck. That's why I am puzzled.
 
In the past I had problems with something similar. It was weird...

Properties_jeo9bi.png


At that time I played a bit with target cpu, and it worked. If I remember well, I was having a problem with inserting a powercopy. Try that.

Tiago Figueiredo
Tooling Engineer

Youtube channel:
 
I have VB 2017 community, but because of familiarity I am initially doing it in VB Express 2010. When I compile (build), I get the following out put.

------ Build started: Project: catBB10, Configuration: Release x86 ------
catBB10 -> F:\Users\0SanjayData\0Jobs\zzzDemos1901\CATIA\catBB10\catBB10\bin\Debug\catBB10.exe
========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========

So, I suppose my target CPU is already x86.

So where do we go next?
 
Solved!!

The problem was somewhere else and finally I could figure it out. Everything works fine now. I converted it into VB 2017 community dll and the dll works fine, at least for the trial part, in the calling program.

I was processing planes in different subs and in one of the subs they were passed ByVal instead of ByRef. So, for min. distance, deleted planes were passed as parameters.

I didn't get the required clue due to the cryptic message "Hresults ...". I checked if planes were 'not is nothing' and every time I found the result false. Instead, if I had got the error message something like "the object does not exist" or the "object is deleted" I would have located the error immediately.

Today, while preparing the code for posting, I did exhaustive debugging to make sure; and realized the error. It was 'Why didn't I do this the first time' moment.

Thanks for your time and efforts, Tiago Figueiredo.

My next task is to validate the code by testing it on multiple parts inside a loop.

 
Status
Not open for further replies.
Back
Top