Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

VBA - manually selecting a 3d object and extracting centroid & volume properties

Hi,
I am currently working in precast concrete manufacturing and want to find an easy way to use a VBA macro to select a single
3d object and automatically draw a 'point' at it's centroid in 3d space.
It would also be useful to extract the volume of the object and display it in cubic metres.
This can then be multiplied by a constant to give the object's weight.

If a simple macro can be used then I would like to develop the program further with more features
using a windowed graphical interface.

Any help, advice or code snippets would be vary helpful and appreciated.

Thanks. Tim

Answers

  • Further to my original post I have had a go at some coding.....see below

    Sub infotest()

    Dim unit As Acad3DSolid
    Dim bpoint As Variant
    Dim ucgp As Variant
    Dim uvolm As Variant
    Dim cgx As Variant
    Dim cgy As Variant
    Dim cgz As Variant
    
    ThisDrawing.Utility.GetEntity unit, bpoint, "Select Unit:"
    ucgp = unit.Centroid
    cgx = ucgp(0)
    cgy = ucgp(1)
    cgy = ucgp(2)
    uvolm = unit.Volume / 1000000000
    
    MsgBox "C of G = " & Format(ucgp(0), "#0") & ", " & Format(ucgp(1), "#0") & ", " & Format(ucgp(2), "#0") & " VOL=" & Format(uvolm, "###0.0#")
    
    ThisDrawing.ModelSpace.InsertBlock ucgp, "d:\development\cofg1.dwg", 1, 1, 1, 0
    

    End Sub

    As it stands, this code allows me to select a 3d object and extract its values for its centroid & volume in cubic mm.
    I pass this data which is formatted to a simple messagebox.

    The macro then inserts a block at the centroid point.

    The block that is being inserted has attributes for various things I need for BofQ work.

    My question is, using VBA can I automatically pass the data extracted above to the block attributes as it is being inserted rather than
    having to do it manually afterwards. The same block for different 3d solids will be inserted as they are selected but will have different values assigned to the attributes depending on shape & size etc.

    Thanks in advance for any help with this.
    Tim

Sign In or Register to comment.
Origami
Origami is the Japanese word for paper folding. ORI means to fold and KAMI means paper and involves the creation of paper forms usually entirely by folding.

Powered by VanillaForums, Designed by Steam