Author Topic: Retrieve objects in a AecWall using VB.net?  (Read 3502 times)

0 Members and 1 Guest are viewing this topic.

mgreven

  • Guest
Retrieve objects in a AecWall using VB.net?
« on: February 01, 2012, 05:42:02 PM »
Hello,

Does someone have a example how to retrieve properties from Aec objects in a Selected AecWall?
I want to let the user select a wall and present the user a list of AecWindows and AecDoors withing the selected wall (if present).

I am able to get the basic properties from the wall as Startpoint etc... but how do i find the AecObjects within the Wall. i know they have anchors, but how does this work in VB.NET?

Regards,

Marco

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Retrieve objects in a AecWall using VB.net?
« Reply #1 on: February 01, 2012, 06:48:51 PM »
*******EDIT**********
Sorry I did not add Welcome to the Swamp!!!
*******EDIT**********
 
GetOpeningsFor method will get windows and doors in wall
Very simple example
 
Code: [Select]
Imports System
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.EditorInput
Imports ObjectId = Autodesk.AutoCAD.DatabaseServices.ObjectId
Imports Autodesk.Aec.DatabaseServices
Imports ArchDbSrvcs = Autodesk.Aec.Arch.DatabaseServices
Imports PipeDbServies = Autodesk.Aec.Building.Piping.DatabaseServices
Imports Autodesk.Aec.Building.DatabaseServices
Imports Autodesk.Aec.Building.ApplicationServices
 

<Assembly: CommandClass(GetType(AutoCADMEPVB2012Examples.MyCommands))>
Public Class MyCommands
    <CommandMethod("WallOpenings")> _
    Public Sub WallOpenings()
        Dim doc As Document = Application.DocumentManager.MdiActiveDocument
        Dim db As Database = doc.Database
        Dim ed As Editor = doc.Editor

        Using trx As Transaction = db.TransactionManager.StartTransaction()
            Dim wallId As ObjectId = ed.GetEntity("Select Wall").ObjectId
            Dim wall As ArchDbSrvcs.Wall = trx.GetObject(wallId, OpenMode.ForRead)

            For Each id As ObjectId In wall.GetOpeningsFor()
                ed.WriteMessage(Environment.NewLine & id.ObjectClass.DxfName)
            Next

            trx.Commit()

        End Using
    End Sub
End Class
« Last Edit: February 01, 2012, 08:42:24 PM by Jeff H »

mgreven

  • Guest
Re: Retrieve objects in a AecWall using VB.net?
« Reply #2 on: February 02, 2012, 03:22:26 AM »
Thanks for the example...

Now i am going to try to get the position of the opening in the wall.
For now i am getting a weird position... i think world coordinates.

i am trying to make a routine to place some MVblocks in the openings found and anchor them to te wall.
It seems a long way to go.

Regards,

Marco

kaefer

  • Guest
Re: Retrieve objects in a AecWall using VB.net?
« Reply #3 on: February 02, 2012, 06:15:50 AM »
i am trying to make a routine to place some MVblocks in the openings found and anchor them to te wall.
It seems a long way to go.

It's not quite as long if you can stand on the shoulders of dwarfs. I had a go at the same problem (anchoring a tag to a Geo, the most general Aec object which supports anchoring), which can be found here.

It may be that the way in which the anchoring  point is determined could be much improved, but here goes anyway (br is a MultiViewBlockReference):
Code - C#: [Select]
  1.                 aecDb.Anchor anc =
  2.                     new AnchorExtendedTagToEntity()
  3.                     {
  4.                         ReferencedEntityId = geoId,
  5.                         AllowIndependentUpdate = true,
  6.                         ForceHorizontal = false
  7.                     };
  8.                 br.SetAnchor(anc);
  9.                 br.TransformBy(geo.Ecs.Inverse());
« Last Edit: February 02, 2012, 08:32:21 AM by kaefer »