See the top rated post in this thread. Click here

Results 1 to 7 of 7

Thread: Is it possible to extract area and length of a certain polyline in one field expression?

  1. #1
    Member
    Join Date
    2009-09
    Posts
    5
    Login to Give a bone
    0

    Default Is it possible to extract area and length of a certain polyline in one field expression?

    Hi!

    *First an introduction:
    In our office we use a roomtag-block to identify all the individual rooms in a drawing.
    This block contains room information in multiple attributes: roomname, roomnumber, ceiling heigth, area.

    The area-attribute already contains a field that is linked to a polyline surrounding each individual room.

    I modified acfields.fdc to customize the area-field expression.

    <FormatType name="Area">
    <Formats>
    <!--added by me Jan Van der Borght-->
    <Format>
    <DisplayName>Square meters (VK)</DisplayName>
    <FormatString>%lu2%pr2%ps[, m²]%ct8[1e-006]</FormatString>
    </Format>
    <!--end-->

    *Now the questions:
    At the moment we also have to add the length-attribute to our roomtag-block to calculate the perimeter of each room.

    1. Is there a possibility to reuse the same ObjId (the same polyline, I used to calculate the area) in the field expression for length?
    %<\AcObjProp.16.2 Object(%<\_ObjId 8796088038784>%).Area \f "%lu2%pr2%ps[, m²]%ct8[1e-006]">%
    This way I don't have to manually add 2000 new length-attributes.

    2. Or is it possible to combine 2 field expressions in one to automatically display the area and perimeter of a selected polyline in one field?
    Something like this:
    %<\AcObjProp.16.2 Object(%<\_ObjId 8796088038784>%).Area \f "%lu2%pr2%ps[, m²]%ct8[1e-006]">%;%<\AcObjProp.16.2 Object(%<\_ObjId 8796088038784>%).Length \f "%lu2%pr2%ps[, m]%ct8[0.001]">%
    Do I have to use a formula or lsp to achieve this?

    Big thanks in advance!
    Jan

  2. #2
    All AUGI, all the time arshiel88's Avatar
    Join Date
    2005-02
    Location
    Off the Grid
    Posts
    560
    Login to Give a bone
    0

    Default Re: Is it possible to extract area and length of a certain polyline in one field expression?

    I'm not familiar with the acfields.fdc, I don't exactly get why you need to edit this.

    About your question of combining fields, Yes. In fact you can insert a second field after the other. You can even insert a field inside a field.
    Copy to clipboard the combined field expression then paste directly to a text contents and it will be automatically evaluated. (Is this the reason why you edit acfields.fdc?) The semi-colon you put between expression will become a literal semi-colon because there's no need to separate them with any character save for characters that will appear in the text.

    Shielbern Bolalin
    Architectural 3D Renderer
    ----------------------------------------------------------------------
    “A clever person solves a problem. A wise person avoids it.”

    1879-1955

  3. #3
    Member
    Join Date
    2009-09
    Posts
    5
    Login to Give a bone
    0

    Default Re: Is it possible to extract area and length of a certain polyline in one field expression?

    Hey arshiel88, thanks for your reply! You're right, the modified acfields.fdc wasn't usefull to mention here.

    After some brainstorming I think I need to change the title of this thread: it should be 'Please help me writing LSP or VBA-code to fill in a field automatically'.
    I'm looking for a way to fill in the perimeter of a room as attribute in the block RoomInformation [Lokaalgegevens in Dutch] when the area of this room has already been calculated by using a polyline .

    Visually explained:

    image001.png
    1. Open the attribute editor.
    2. Doubleclick on the field of the area [Ruwbouwppervlakte in Dutch]

    image002.png
    3. Select Length as Property (because we want to know the perimeter of the same polyline that has been used to calculate the area.)
    4. Copy the expression from 'Field Expression'

    image003.png
    5. Paste this expression in the attribute editor as Value for the Perimeter-attribute [Omtrek in Dutch].
    6. The result is the perimeter of the same polyline as the polyline that is used to calculate the area.

    To avoid that we need to copy-paste this field expression >2000 times, I'm looking for some VBA or LSP-code to automatically fill in all the perimeter-attributes.
    Is this possible?

  4. #4
    All AUGI, all the time arshiel88's Avatar
    Join Date
    2005-02
    Location
    Off the Grid
    Posts
    560
    Login to Give a bone
    0

    Default Re: Is it possible to extract area and length of a certain polyline in one field expression?

    I can't help you with the Lisp but here's to try for VBA.
    Create a block with attributes;

    1. for Area Tag: AREA
    2. for Perimeter Tag: PERIMETER

    Then run this macro
    Code:
    Sub PerimeterAreaBlock()
    
    Dim strObjectID As String
    Dim xBlock As AcadBlockReference
    Dim objPolyline As AcadLWPolyline
    Dim varAttribs As Variant
    
    On Error Resume Next
    ThisDrawing.Utility.GetEntity xBlock, pt1, "Select Block"
    If Err Then Exit Sub
    ThisDrawing.Utility.GetEntity objPolyline, pt1, "Select polyline"
    If Err Then Exit Sub
    
    strObjectID = ThisDrawing.Utility.GetObjectIdString(objPolyline, False)
    AreaFieldStr = "%<\AcObjProp.16.2 Object(%<\_ObjId " & strObjectID & ">%).Area \f ""%lu2%pr2%ps[, m²]%ct8[1e-006]"">%"
    LengthFieldStr = "%<\AcObjProp.16.2 Object(%<\_ObjId " & strObjectID & ">%).Length \f ""%lu2%pr2%ps[, m]%ct8[0.001]"">%"
    
    varAttribs = xBlock.GetAttributes
    
    For i = 0 To UBound(varAttribs)
        Select Case varAttribs(i).TagString
            Case "PERIMETER"
                varAttribs(i).TextString = LengthFieldStr
            Case "AREA"
                varAttribs(i).TextString = AreaFieldStr
        End Select
    Next
    
    ThisDrawing.Regen acActiveViewport
    
    End Sub
    I think this is better than to extract (but its also possible) the ObjectID from the field expression of the area attribute. The defining polyline is still there right? Or else the field wont work. What do you think?

    Shielbern Bolalin
    Architectural 3D Renderer
    ----------------------------------------------------------------------
    “A clever person solves a problem. A wise person avoids it.”

    1879-1955

  5. #5
    Member
    Join Date
    2009-09
    Posts
    5
    Login to Give a bone
    0

    Default Re: Is it possible to extract area and length of a certain polyline in one field expression?

    Thanks for the fast reply!
    I'll try to implement your code the next week, I'll keep you up-to-date!

  6. #6
    Member
    Join Date
    2009-09
    Posts
    5
    Login to Give a bone
    0

    Default Re: Is it possible to extract area and length of a certain polyline in one field expression?

    do I need to install the the Microsoft Visual Basic for Applications Module first for this to work?
    http://usa.autodesk.com/adsk/servlet...linkID=9240618

  7. #7
    All AUGI, all the time arshiel88's Avatar
    Join Date
    2005-02
    Location
    Off the Grid
    Posts
    560
    Login to Give a bone
    1

    Default Re: Is it possible to extract area and length of a certain polyline in one field expression?

    Yes. Its not included in the installation in the later releases because their trying to abolish it.

    Shielbern Bolalin
    Architectural 3D Renderer
    ----------------------------------------------------------------------
    “A clever person solves a problem. A wise person avoids it.”

    1879-1955

Similar Threads

  1. Polyline Area Field Command ??
    By bellis.239472 in forum AutoCAD General
    Replies: 1
    Last Post: 2010-03-19, 08:19 PM
  2. Trouble with Length (Area) of Polyline
    By rod.238423 in forum AutoCAD Customization
    Replies: 4
    Last Post: 2010-02-19, 09:22 PM
  3. Customizing field expression
    By amarkovi in forum Dynamic Blocks - Technical
    Replies: 5
    Last Post: 2009-03-31, 06:00 PM
  4. Area Label Expression Length
    By eleonard in forum AutoCAD Civil 3D - Parcels
    Replies: 1
    Last Post: 2008-07-25, 07:28 PM
  5. Field expression change
    By csiress in forum AutoCAD Fields
    Replies: 3
    Last Post: 2007-11-20, 06:37 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •