VB code not giving physical properties ??

 

hi

can anybody check why the code is not giving physical properties please

Sub Main()

Dim objApp As SolidEdgeframework.Application

Dim objDoc As SolidEdgePart.PartDocument

Dim objModel As SolidEdgePart.Model

Dim objVars As SolidEdgeframework.Variables

Dim objVar As SolidEdgeframework.Variable

Dim a As Double

Dim b As Double

Const TOLERANCE = 0.0001

Dim dblDensity As Double

Dim dblAccuracyIn As Double

Dim dblAccuracyOut As Double

Dim dblVolume As Double

Dim dblArea As Double

Dim dblMass As Double

Dim dblCofGravity() As Double

Dim dblCofVolume() As Double

Dim dblGlobalMoments() As Double

Dim dblPrincipalMoments() As Double

Dim dblPrincipalAxes() As Double

Dim dblRadiiOfGyration() As Double

Dim lngStatus As Long

 

' Report errors

Const PI = 3.14159265358979

' Create/get the application with specific settings

On Error Resume Next

Set objApp = GetObject(, "SolidEdge.Application")

If Err Then

Err.Clear

Set objApp = CreateObject("SolidEdge.Application")

Set objDoc = objApp.Documents.Add("SolidEdge.PartDocument")

objApp.Visible = True

Else

Set objDoc = objApp.ActiveDocument

End If

 

Call objApp.Documents.Open("h:\vbsolid\cylinder.par")

Set objVariables = objApp.ActiveDocument.Variables

 

a = 350

b = 1250

 

Call objVariables.Edit("var1", a)

Call objVariables.Edit("var2", b)

Set objModel = objDoc.Models(1)

dblDensity = 1

dblAccuracyIn = 0.0001

Call objModel.ComputePhysicalProperties( _

Density:=dblDensity, Accuracy:=dblAccuracyIn, Volume:=dblVolume, _

Area:=dblArea, Mass:=dblMass, CenterOfGravity:=dblCofGravity, _

CenterOfVolume:=dblCofVolume, _

GlobalMomentsOfInteria:=dblGlobalMoments, _

PrincipalMomentsOfInteria:=dblPrincipalMoments, _

PrincipalAxes:=dblPrincipalAxes, _

RadiiOfGyration:=dblRadiiOfGyration, _

RelativeAccuracyAchieved:=dblAccuracyOut, Status:=lngStatus)

' Checking the physical properties of model

If Abs(dblVolume - 0.001) > TOLERANCE Or Abs(dblArea - 0.06) > TOLERANCE Or _

Abs(dblMass - 0.001) > TOLERANCE Or Abs(dblAccuracyOut - 0.0001) > TOLERANCE Then

MsgBox ("ComputePhysicalProperties method of Model object fails")

End If

 

Set objApp = Nothing

Set objDoc = Nothing

Set objVars = Nothing

Set objVar = Nothing

Set objModel = Nothing

End Sub

 

Posted by: ali kamran
Post date: 12/8/2008 2:30:34 AM

14 REPLIES

RE: VB code not giving physical properties ??

 

Dear Ali

i think the code should work, but let it be

you can use save after updating the variables and try.

 

the same code is there in solidedge programming help.

code is different for part and assembly for computing the physical properties

try it

all the best

 

 

Posted by: Sandeep Shewale
Post date: 12/15/2008 9:08:28 PM

RE: VB code not giving physical properties ??

 

I did used SAVE but still useless....

but one more thing i want to add

when i use only

dblVolume = objBody.Volume

it gives the volume of the object...

Sandeep ...any idea

regards

 

 

Posted by: ali kamran
Post date: 12/21/2008 2:24:22 AM

RE: VB code not giving physical properties ??

 

 Dim objApp As SolidEdgeframework.Application

Dim objDoc As SolidEdgePart.PartDocument

Dim objModel As SolidEdgePart.Model

Dim objVars As SolidEdgeframework.Variables

Dim objVar As SolidEdgeframework.Variable

Dim a As Double

Dim b As Double

Const TOLERANCE = 0.0001

Dim dblDensity As Double

Dim dblAccuracyIn As Double

Dim dblAccuracyOut As Double

Dim dblVolume As Double

Dim dblArea As Double

Dim dblMass As Double

Dim dblCofGravity() As Double

Dim dblCofVolume(1 To 3) As Double

Dim dblGlobalMoments(1 To 6) As Double

Dim dblPrincipalMoments(1 To 3) As Double

Dim dblPrincipalAxes(1 To 9) As Double

Dim dblRadiiOfGyration(1 To 3) As Double

Call objModel.ComputePhysicalProperties(.............................)

'Try to retrieve the values by declaring the variables

vol = dblVolume

area = dblArea

covx = dblCofVolume(1)

covy = dblCofVolume(2)

covz = dblCofVolume(3)

I have not tested the code but think i should work.

 

Posted by: Prasad Pawar
Post date: 12/21/2008 7:29:17 PM

RE: VB code not giving physical properties ??

Did change the things ....

still not working ....

dont know even if SE can give the properties other than volume hehehe

Regards

Ali

 

Posted by: ali kamran
Post date: 12/30/2008 3:00:51 AM

RE: VB code not giving physical properties ??

Solid Edge will correctly compute and expose Physical Properties. What particular property are you seeking? What units are you working in? Are you trying to dynamically change the value of a property and recompute?

 

Posted by: Bill Ledbetter
Post date: 12/31/2008 12:54:47 AM

RE: VB code not giving physical properties ??

I need volume ,inertias(principal and global),center of gravity etc

i m working in mm ...

i want to dynamically chenge the modle and get the properties

check if you can make it work

regards

Ali

 

Posted by: ali kamran
Post date: 12/31/2008 3:13:41 AM

RE: VB code not giving physical properties ??

Are you having the original values returned or is it returning and error? Where did the variable names of "var1" and "var2" come from? Did you rename them in the variable table?

 

The code will dynamically alter a variable and recompute, assuming the variable names match.

 

Posted by: Bill Ledbetter
Post date: 1/5/2009 1:22:06 AM

RE: VB code not giving physical properties ??

No it gives an arror .....no values at all.

i made these variables var1 var2 . in the variable table. i checked the variables value are changing so no problem in it.

 

if i use """ dblvolume """" command only it gives the volume.

 

it i use """ Call objModel.ComputePhysicalProperties """

 

then it gives error""""""""("ComputePhysicalProperties method of Model object fails")""""""

this is the situation...

regards

Ali

 

 

Posted by: ali kamran
Post date: 1/5/2009 6:04:17 PM

RE: VB code not giving physical properties ??

Bill .i was checking the code and find out one thing;;;;

 

1. If i change the value of " dblAccuracyIn " in vb code after running I check the value in INSPECT/PHYSICALPRPERTIES ..the value is changed.

 

2. The value of " dblDensity " dosent change remains ZERO in INSPECT/PHYSICALPRPERTIES ....

 

dont know why?

Regards

Ali

 

Posted by: ali kamran
Post date: 1/5/2009 11:08:27 PM