Author Topic: [Newbie Help] Input X,Y of all instances of block into new table  (Read 7091 times)

0 Members and 1 Guest are viewing this topic.

jnieman

  • Guest
I have a block.  It is put into the drawing as a datum point for an equipment layout sheet for a facility we are designing.  This happens often enough to warrant automation, as our current process is very manual.

We provide a table that states: Name, Northing, Easting, Elevation (manually entered) and Description

The only thing I'm wanting to automate is the Northing and Easting which is the same as it's Y and X values.

I wish to have the user select a block to populate a table from, and have the table created.

I have not gotten as far as creating the table, because all I can find information on is how to create a basic table... nothing about adding rows, setting text... (setText gives me an error, see following) or anything like that.

What I have so far:

Code: [Select]
Sub DatumTable()

Dim Block As AcadBlockReference
Dim DatumObj As AcadObject
Dim TableObj As AcadTable
Dim filterType(0) As Integer
Dim filterData(0) As Variant
Dim selSet As AcadSelectionSet

GetEnt: 'Start loop point

    ThisDrawing.Utility.GetEntity DatumObj, ReturnPnt, "Select a block: "

    If DatumObj.ObjectName <> "AcDbBlockReference" Then

    MsgBox "The selected object wasn't a block!", vbExclamation

GoTo GetEnt 'Goto loop point

End If

Set selSet = ThisDrawing.SelectionSets. _
             Add("DatumObj")


'Create that Table!

    Dim MyPaperSpace As AcadPaperSpace
    Set MyPaperSpace = ThisDrawing.PaperSpace
    Dim pt(2) As Double
    Dim MyTable As AcadTable
    Set MyTable = MyPaperSpace.AddTable(pt, 1, 2, 3, 4)
    MyTable.RegenerateTableSuppressed = True

   
   
    MyTable.RegenerateTableSuppressed = False

End Sub

In addition, the setText from the Autocad Developer's Guide Help shows this:

Code: [Select]
object.SetText(row, col, pStr)
but if I use
Code: [Select]
MyTable.SetText(1, 1, Text)It errors, saying it expects an "=" .... I don't get why.

Jeff_M

  • King Gator
  • Posts: 4094
  • C3D user & customizer
Re: [Newbie Help] Input X,Y of all instances of block into new table
« Reply #1 on: July 17, 2008, 11:44:42 AM »
In VBA when you provide arguments to a method, IF you are also using a variable for future use, THEN you use the parenthesis:
Code: [Select]
Dim OTbl As AcadTable
Dim vInsPt(2) As Double
Set OTbl = ThisDrawing.ModelSpace.AddTable(vInsPt, 1, 1, 5, 10)
However, when you are not assigning the return value to a variable, no parenthesis are used. To make this even more confusing, although we defined the table to have 1 row & 1 column, these need to be accessed in a Zero based array. So to use SetText on my Table example we use this:
Code: [Select]
OTbl.SetText 0, 0, "MyText"
Does that help?

jnieman

  • Guest
Re: [Newbie Help] Input X,Y of all instances of block into new table
« Reply #2 on: July 17, 2008, 11:54:07 AM »
Wow.

I understand what you're saying, and now see the difference in what I should do... but... yea... confusing is right.  That type of syntax seems so strange to me.

of course my boss came and was looking over my shoulder at what I was doing as I was implementing some of fixo's help, and just went "wow.  That's a whole lot different than when we were using FORTRAN back in college"  :-D

jnieman

  • Guest
Re: [Newbie Help] Input X,Y of all instances of block into new table
« Reply #3 on: July 17, 2008, 02:52:48 PM »
I'm starting to wonder if I understood what you said as much as I thought I did.


Code: [Select]
    Dim ID As String
    Dim Desc As String
Code: [Select]
            ID = oBlk.GetAttribute(ID)
            Desc = oBlk.GetAttribute(Desc)

I am defining those variables to be strings, assigning a value directly to them there, and then later, accessing that value and putting it into the celltext via SetText.

When running the routine I get an error:
Quote
Runtime error 438:
Object doesn't support this property or method

Am I not understanding, or am I looking to the wrong place for the error?

*edit*

the block -does- have attributes named "ID" and "DESC" in it.

Jeff_M

  • King Gator
  • Posts: 4094
  • C3D user & customizer
Re: [Newbie Help] Input X,Y of all instances of block into new table
« Reply #4 on: July 17, 2008, 05:48:45 PM »
Based on your questions in your other thread and this last one, maybe this will help.....

If a BlockRef has attributes, then you get ALL of them like so:
Code: [Select]
Dim vAtts at Variant
vAtts = oBlk.GetAttributes
Now vAtts will be an array holding all of the defined attributes. To find out how many there are, use UBound(vAtts), which gives you the Upper Boundary of the Array. But remember, this is 0 based, so add 1 for the total number (if you want to know this). Now, to obtain the data for each one, loop thru the array.
Code: [Select]
Dim I as Integer
Dim oAtt as AcadAttributereference

For I = 0 to UBound(vAtts)
   Set oAtt = vAtts(I)
   Select Case oAtt.TagString
      Case Is = "ID"
         'fill the correct cell with the oAtt.TextString
      Case Is = "DESC"
         'fill the correct cell with the oAtt.TextString
      Case is = "OTHER"
         'fill the correct cell with the oAtt.TextString
     'etc....
   End Select
Next I
I hope that clears it up a bit.

jnieman

  • Guest
Re: [Newbie Help] Input X,Y of all instances of block into new table
« Reply #5 on: July 17, 2008, 06:46:18 PM »
WOOOOOOOOOOOOOO!!!!!!!!!!!!!!!!!!!!HOOOOOOOOOOOOOOO!!!!!!!!!!!!!!!!!!!!!!!!!!

This is the most glorious table I've ever created in Autocad!

Code: [Select]
Option Explicit
Sub Blocks_Table()

    Dim oAtt As AcadAttributeReference
    Dim oSset As AcadSelectionSet
    Dim oEnt As AcadEntity
    Dim oBlk As AcadBlockReference
    Dim varPt As Variant
    Dim ftype(0) As Integer
    Dim fdata(0) As Variant
    Dim bName As String
    Dim xStr As String
    Dim yStr As String
    Dim vAtts As Variant
    Dim I As Long, j As Long
    Dim C As Integer

    ftype(0) = 0: fdata(0) = "INSERT"
    Dim dxfCode, dxfValue
    dxfCode = ftype: dxfValue = fdata

    With ThisDrawing.SelectionSets
        While .Count > 0
            .Item(0).Delete
        Wend
        Set oSset = .Add("$Blocks$")
    End With
   
    ThisDrawing.ActivePViewport.Display True
    ThisDrawing.ActiveSpace = acModelSpace

    oSset.SelectOnScreen dxfCode, dxfValue
   
    ThisDrawing.ActiveSpace = acPaperSpace
   
    Dim paSpace As AcadPaperSpace
    Set paSpace = ThisDrawing.PaperSpace
   
    varPt = ThisDrawing.Utility.GetPoint(, vbCrLf & "Specify insertion point: ")
    Dim oTable As AcadTable
    Set oTable = paSpace.AddTable(varPt, oSset.Count + 3, 6, 0.3, 1.5)
    oTable.TitleSuppressed = False
    oTable.HeaderSuppressed = True
   
    ZoomExtents
    With oTable
    .RegenerateTableSuppressed = True
   
        .SetCellTextHeight I, j, 0.15625
        .SetCellAlignment I, j, acMiddleCenter
        .SetCellType I, j, acTextCell
        .SetText 0, 0, "EQUIPMENT LAYOUT SCHEDULE"
   
        .SetText 1, 0, "ITEM"
        .SetCellTextHeight 1, 0, 0.09375
        .SetText 1, 1, "EQUIPMENT DATUM"
        .SetCellTextHeight 1, 1, 0.09375
        .SetText 1, 4, "DATUM LOCATION"
        .SetCellTextHeight 1, 4, 0.09375
        .SetText 1, 5, "DESCRIPTION"
        .SetCellTextHeight 1, 5, 0.09375
       
        .SetText 2, 1, "N"
        .SetCellTextHeight 2, 1, 0.09375
        .SetText 2, 2, "E"
        .SetCellTextHeight 2, 2, 0.09375
        .SetText 2, 3, "EL"
        .SetCellTextHeight 2, 3, 0.09375
       
        For I = 0 To oSset.Count - 1

            Set oEnt = oSset.Item(I)
            Set oBlk = oEnt
            If oBlk.IsDynamicBlock Then
                bName = oBlk.EffectiveName
            Else
                bName = oBlk.Name
            End If
            xStr = Format(CStr(Round(oBlk.InsertionPoint(1), 3)), "#0.000")
            yStr = Format(CStr(Round(oBlk.InsertionPoint(0), 3)), "#0.000")
           
            .SetCellTextHeight I + 3, j, 0.09375
            .SetCellAlignment I + 3, j, acMiddleCenter

            .SetText I + 3, j + 1, xStr
            .SetCellTextHeight I + 3, j + 1, 0.09375
            .SetText I + 3, j + 2, yStr
            .SetCellTextHeight I + 3, j + 2, 0.09375

    vAtts = oBlk.GetAttributes
        For C = 0 To UBound(vAtts)
           Set oAtt = vAtts(C)
          Select Case oAtt.TagString
              Case Is = "ID"
            .SetText I + 3, 0, oAtt.TextString
            .SetCellTextHeight I + 3, 0, 0.09375
              Case Is = "DESC"
            .SetText I + 3, 5, oAtt.TextString
            .SetCellTextHeight I + 3, 5, 0.09375
              Case Is = "ELEVATION"
            .SetText I + 3, 3, oAtt.TextString
            .SetCellTextHeight I + 3, 3, 0.09375
              Case Is = "DATUMLOC"
            .SetText I + 3, 4, oAtt.TextString
            .SetCellTextHeight I + 3, 4, 0.09375

           End Select
        Next C
        Next I
   
        oTable.MergeCells 1, 2, 0, 0
        oTable.MergeCells 1, 2, 4, 4
        oTable.MergeCells 1, 2, 5, 5
        oTable.MergeCells 1, 1, 1, 3
   
    .RegenerateTableSuppressed = False
   
    .Update
   
    End With
       
    MsgBox "Yahoooooo!"

End Sub

Is the final code.

I will do some tweaking, maybe add some conditional error trapping, or command-line instructions so the user knows what s/he's required to do, but for now I'm the one using it, so this gets me by for now.

The example shown is three tanks... I have NUMEROUS tanks of different types, pumps, ventilators, dust collectors, sumps, and on and on and on...that I need to fill in...

This will most surely be a godsend as we do these... equipment layouts were the biggest thorn to me until now.  So menial filling out that schedule by hand!

I thank you (and fixo) so much for this.

I've learned a GREAT deal along the way.... so much... I think my head may explode if I don't call it a day, for now.

Thank you again.

Jeff_M

  • King Gator
  • Posts: 4094
  • C3D user & customizer
Re: [Newbie Help] Input X,Y of all instances of block into new table
« Reply #6 on: July 17, 2008, 07:09:40 PM »
Congratulations! You are most welcome for the little tidbits I was able to toss your way.

jnieman

  • Guest
Re: [Newbie Help] Input X,Y of all instances of block into new table
« Reply #7 on: July 17, 2008, 08:15:56 PM »
now imagine filling out that table by hand for around 100+ objects... selecting a block... hitting "LI" reading the coordinates... typing them in the table... typing in the miscellanious info... and doing that 100 times over... oh... and then revisions!

*Josh, updated the site plan, the county demanded we add 5' to the utility easement on the west end, so we shifted the entire tank farm over, can I have that updated asap?*

*goes through each cell, adding 5.0 to each entry on the Easting another 100 times*

yea... I'm happy to have this.

CadRover

  • Guest
Re: [Newbie Help] Input X,Y of all instances of block into new table
« Reply #8 on: July 21, 2008, 03:48:55 AM »

Ahhh
Northing and Easting
Land Desktop huh?
or
Civil 3D

If I recall, most people do not set their Nothing and Easting Settings.

Dropping geo-spatial arials on the proper datum is really cool

And GIS is so up and coming as well.

BTW: If you are using one of the two products that I mentioned, you cn get to their specific object tyes as well in VBA

Cadr

jnieman

  • Guest
Re: [Newbie Help] Input X,Y of all instances of block into new table
« Reply #9 on: July 21, 2008, 08:45:58 AM »
Nope, vanilla Autocad for me :D

It's dumb X and Y, for me... I just call it northing and easting :P

CadRover

  • Guest
Re: [Newbie Help] Input X,Y of all instances of block into new table
« Reply #10 on: July 21, 2008, 04:43:20 PM »

Oh LOL
God, I have been doinng ACAD for almost 15 years andi never heard of Northing and Easting til I worked at a Civil Design firm.
Fortunately and Unfortunately, I am much better at Vanilla as well.
I did do any design while there, but I needed to understand Land Desktop to some degree to do automation projects

Cadr

CadRover

  • Guest
Re: [Newbie Help] Input X,Y of all instances of block into new table
« Reply #11 on: July 21, 2008, 04:47:39 PM »

Not to bore you but the concept of intelligent aerials and GIS as it relates to datums in ACAD is fascinating.

I was once screwing around with some geo-spatially correct aerials of Philadelphia.

I chose the proper datum and they were inserting precisely where there would according to World Coordinates.

I thought it was pretty cool!

Of course there were people there screwing with cropping and pasting, trying to fudge it in.

That is how I got involved.
It is kind of like hello...
Let the app do the work for you, but of course they had to learn, as did I.

Cadr

jnieman

  • Guest
Re: [Newbie Help] Input X,Y of all instances of block into new table
« Reply #12 on: July 21, 2008, 04:51:56 PM »
Well we do civil... but not often.  We're structural and civil, but do a variety.  This is locating machinery and equipment by using a datum point on the machine, and locating it on the site grid.  In this case we're using state plane coordinates, unfortunately.  Someone else did the overall site design, foundation, grading, etc... we're just putting the clients facility on it, all platforms, structures, etc.

I prefer when we pick a monument as a reference point of 100.00' E 100.00' N and work from there.  Example:  at point, X=4.37106E+07  Y=    0'-0"  Z=-232528'-5 1/32"

meh

I'm not too keen on geospatial as the work... but the concepts and abilities and technology -is- fascinating to me.  I like to read about the goings-ons in the GIS world now and then because there's always something interesting going on.

CadRover

  • Guest
Re: [Newbie Help] Input X,Y of all instances of block into new table
« Reply #13 on: July 21, 2008, 05:07:37 PM »

Ahhh
So, when you say equipment and machinery, then I am assuming the exterior equipment, like AC units etc.
I knew you have to have some exposure to Civil to had used the term Northing and Easting; though that is also presumptuous of me.

What happens in LandDesktop, well, I would imagine with other ACAD apps as well; if a CAD user puts their plan way out in east jib it in Model, then it would often eat up a lot of processing power as ACAD has to work that much harder and do far more math.

Therefore, you can have your plan in each jib it; especially if it is on the correct datum, then by making The Northing and Easting = 0,0 it would effectively fake ACAD out into believing that the drawing was in fact at 0,0

Where people would get confused is that if you did a list, it would say nothing and easting cords, but I do believe that it would also give the cords relative to 0,0. For that reason, people weren't setting their Northing and Easting and the problems continued.
Hey, why fix it when you can call your friendly neighborhood support guy, right :)     :-(

Quote
I'm not too keen on geospatial as the work

Why aren't you? I think it is fascinating and seems to be pretty dam accurate.

Yes, the last place I worked at; the one IT guy who was also a seasoned programmer helped to branch that firm into GIS and he is working on a Web Based local township with GIS, Map Guide and .net

The position that I will be interviewing for also has a newly created GIS division to which I will have some involvement, on the development side, so that should be cool.
I have also used CAFM software on two positions, that is Computer Aided Facilities Software; that is very interesting as well.

Cadr

jnieman

  • Guest
Re: [Newbie Help] Input X,Y of all instances of block into new table
« Reply #14 on: July 21, 2008, 05:18:17 PM »
We do such a high variety of work that it's hard to specialize or spend time customizing any one area, I've come to realize, but I always make strides to do so in everything we do.

Yes, it's all exterior equipment but it's a large fluids production facility serving the offshore industry, and consists of a number of large storage tanks, mixing tanks, air compressors, fluid pumps, sumps, electrical transformers, mechanical switchgears, and other such stuff.  We locate all platform column lines and equipment datums on the coords.

We don't get too cocky about the accuracy.  Yes, I have a model that is theoretically 'perfect' and precise to the 8th decimal place or whatever Autocad can handle... but the contractor is only as precise as he wants to be.  The last guy they hired to do one of these facilities ended up with a foundation that somehow grew 12 feet over 500.  I don't consider that very accurate compared to other jobs we've worked on, even in my limited experience.

As for why I'm not "into" GIS too much... dirt work just doesn't tickle my fancy too much I guess.  Surveying less so, as a career.  I admire and respect the technology that has come along but it's not something I would enjoy doing day to day as much as other industries.  That's about all.