×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Simpler way to get Mass Props from dwg view w/ VB

Simpler way to get Mass Props from dwg view w/ VB

Simpler way to get Mass Props from dwg view w/ VB

(OP)
Is Their A Simpler Way To Programmatically Obtain the Mass Properties Of A Model, Given A View In A Drawing, WithOUT physically opening the Model In A new window...?

I know this is possible with Assemblies...
I don't see why it would be impossible with a drawing...

This is A Sample Senario of what I am trying to do...
Assuming the Current View in an Active Drawing is the view I want to retrieve the Mass Properties From...


  Dim swApp As Object, Model As Object, View As Object
  Dim data1 As Variant, data2 As Variant, data3 As Variant
  Dim mass As Double
  Const swDocPART = 1, swDocASSEMBLY = 2, swDocDRAWING = 3

  Set swApp = CreateObject("SldWorks.Application")
  Set Model = swApp.ActiveDoc
  Set View = Model.GetFirstView
  Set View = Model.GetNextView
  
  s$ = View.GetReferencedModelName()
  drawname$ = Model.GetPathName() 'Store current Doc
  Set Model = swApp.ActivateDoc(s$)
    data1 = Model.GetMassProperties()
    massp = round(data1(5) * 2.2046, 2)
    MP_Volume = round(data1(3) * 61023.74, 3)
    MP_Density = round(massp / MP_Volume, 3)

    '...Able to Change Density Here

    mass = Round(MP_Volume * MP_Density, 2)
  Set Model = swApp.ActivateDoc(drawname$) 'reStore Doc


And the Assembly Method (using component objects)...
  Set Configuration = Model.GetActiveConfiguration()
  Set Component = Configuration.GetRootComponent()

  If Component Is Nothing Then        ' If no component, then exit
      Exit Sub
  End If
        
  componentName = Component.Name      ' Get the component name
    
  Set modelD = Component.GetModelDoc()
  Data1 = Component.GetModelDoc().GetMassProperties()
  
  massp = Round((Data1(5) * 2.2046, 2)
  MP_Volume = Round((Data1(3) * 61023.74, 3)
  MP_Density = Round((massp / MP_Volume, 3)
    
  s1$ = "         Mass:" + Str(massp)
  s2$ = ",        Volume:" + Str(MP_Volume)
  s3$ = ",        Density:" + Str(MP_Density)


If you have any Ideas, or if you see something I missed, please let me know...

RE: Simpler way to get Mass Props from dwg view w/ VB

How about adding the mass properties of the model, as a configuration-specific property in the Model? This will get updated while the model is open, and you can then link to the model properties from your drawing view.

RE: Simpler way to get Mass Props from dwg view w/ VB

(OP)
Thanks for your post and ideas
It's just not quite what I am looking for...

I would do this, myself, the trick is getting the other 300 SW users here to do the same...

The Top example works, but it has to physically open the document in another child window... and some times stays active... I could close it, but if it is already opened and not saved, SW does not warn you and closes it any way (bye, bye, changes)... I know this from experience (unfortunately)...

I know the model is loaded in memory when you open a drawing, due to the fact you can make views of it, shade the drawing, pull dimensions off of it, etc...

I am just looking for a "bridge" between the referenced document in a View Object and a Component Object and be able to derive a Model Object from this...

The reason for this is that we have a standard title block for our drawings...

I have made several programs to fill in the title block with an external App...

One of the title block fields is the weight of the part...

Like I said, so far the Top Example works 'OK' but could work better if it could get the Mass Props in the background, not by activateing a part model window...

Thanks,
--Josh--

RE: Simpler way to get Mass Props from dwg view w/ VB

Josh,

If the model is already loaded, which can be checked using

View.IsModelLoaded

then is is poosible to access the model using

Set Model = swApp.GetOpenDocumentByName(View.GetReferencedModelName())

This does not make the document visible, but does allow you to access the mass properties. :)

Also, I recommend using

Option Explicit

at the start of your module as it makes it easier to debug.

Nathan

RE: Simpler way to get Mass Props from dwg view w/ VB

(OP)
Thanks,
  I'll try that when I get back to work...

I had been looking for a GetModel() or GetPart() or something...

I forgot about swApp.GetOpenDocumentByName()

I figured I overlooked something...

btw... I do use Option Explicit...
That was a make-shift clip from a SolidWorks interface module I have been building...

All together it is about 500 - 700 lines, I didn't feel like pasting the whole thing...

RE: Simpler way to get Mass Props from dwg view w/ VB

(OP)
Thanks,
  ...after you establish a View object...
This works great...

  If Not View.IsModelLoaded() Then View.LoadModel
  Set Model = swApp.GetOpenDocumentByName(View.GetReferencedModelName)

  Data1 = Model.GetMassProperties()
  
  massp = Round(Data1(5) * 2.2046, 4)
  MP_Volume = Round(Data1(3) * 61023.74, 4)
  MP_Density = Round(massp / MP_Volume, 3)
    
  s1$ = "  Mass:" + Str(massp)
  s2$ = "  Volume:" + Str(MP_Volume)
  s3$ = "  Density:" + Str(MP_Density)


Thanks for the Tip... Have a Star

RE: Simpler way to get Mass Props from dwg view w/ VB

(OP)
BTW...

The BEST way to do this is like this...


'*** Model Mass Graber ** JDS 7/1/03 ***
  If Not View.IsModelLoaded() Then View.LoadModel
  Set Model = swApp.GetOpenDocumentByName(View.GetReferencedModelName)
  
Model.ShowConfiguration (View.ReferencedConfiguration)
  mpData = Model.GetMassProperties()
  
  massp = Round(mpData(5) * 2.2046, 4)
  MP_Volume = Round(mpData(3) * 61023.74, 4)
  MP_Density = Round(massp / MP_Volume, 3)
'***************************************

This Way you get the actual Mass Properties of the configuration in the view... Not whatever configuration it was last saved as...

Thanks,
--Josh--

RE: Simpler way to get Mass Props from dwg view w/ VB

No *wonder* my code seems to run so slow... Ive been coding in all BLACK INK .

RE: Simpler way to get Mass Props from dwg view w/ VB

My First star! I'm so happy :)

Glad I could help Josh.

Nathan

RE: Simpler way to get Mass Props from dwg view w/ VB

(OP)
... Yeah, the Blue ink is sure to work...

But don't use the green ink to often... It acts like it's not even there...
And red ink gives you head aches and just doesn't like to run

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources