VB.NET accessing property set data

VB.NET accessing property set data

Anonymous
Not applicable
1,728 Views
3 Replies
Message 1 of 4

VB.NET accessing property set data

Anonymous
Not applicable
Hi, I wish to migrate my VBA code into VB.NET.

Here is a snippet of the code i use in VBA. From the research i have done i believe the below is possible in VB.NET too, with the addition of some libaries.

Could someone please provide the libaries required and/or sample code of how to achieve the below in VB.NET

Dim Sched As New AecScheduleApplication
Dim PropSets As AecSchedulePropertySets
Dim propSet As AecSchedulePropertySet
Dim Prop As AecScheduleProperty
Set PropSets = Sched.PropertySets(vDoor)
For i = 0 To PropSets.Count - 1
Set propSet = PropSets.Item(i)
If propSet.name = vpropSet Then
ansi = i
Exit For
End If
Next i


Regards

Chris
0 Likes
1,729 Views
3 Replies
Replies (3)
Message 2 of 4

cadMeUp
Collaborator
Collaborator
In your vb net project you need to add reference's to the AEC libraries. In Visual Studio goto the 'Project' menu, select 'Add Reference...', click on the 'COM' tab and scroll down until you see the libraries starting with 'AEC'. You should add 'AEC Base', 'AEC Architectural', and 'AEC Schedule'

The library versions depend on what version of AutoCAD/Architectural you are using. I am using 2008 and those libraries are:
AEC Architectural 5.5 Application Library
AEC Architectural 5.5 Object Library
AEC Base 5.5 Application Library
AEC Base 5.5 Object Library
AEC Schedule 5.5 Object Library

Also scroll down until you see 'AutoCAD/ObjectDBX Common **.* Type Library' and add that as well.

Also make sure your project has references to
'acmgd & acdbmgd'.

Add these to the top of your code file:
Imports Autodesk.AutoCAD.Interop
Imports Autodesk.AutoCAD.Interop.Common
Imports Autodesk.AEC.Interop.Schedule
Imports Autodesk.AEC.Interop.ArchBase

I got your code to compile in VS 2005 using AutoCAD MEP 2008 which has Archtectural.
0 Likes
Message 3 of 4

Anonymous
Not applicable
Thank you for your reply,

I think my issue is the way im getting the aec object from the using input. I get the following error when i run the below code, "Unable to cast object of type 'Autodesk Aec.Structural.DatabaseServices.Member' to type 'Autodesk.AutoCAD.Interop.Common.AcadObject'

Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.EditorInput

Imports Autodesk.AutoCAD.Interop
Imports Autodesk.AutoCAD.Interop.Common
Imports Autodesk.AEC.Interop.Schedule
Imports Autodesk.AEC.Interop.ArchBase

Namespace Selection

Public Class AcEdSSGetCommand

Shared SelentityCount As Integer = 0
Shared UseThisSelectionResult As PromptSelectionResult
Shared UseThisSelectionOption As PromptSelectionOptions = Nothing

'This command allows only a single entity to be picked
_
Public Sub singlePick()
Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
Dim Opts As New PromptSelectionOptions()
Opts.AllowDuplicates = True
Opts.MessageForAdding = "Select entities"
Dim res As PromptSelectionResult = ed.GetSelection(Opts)

If res.Status = PromptStatus.Error Then
Return
End If

Dim SS As Autodesk.AutoCAD.EditorInput.SelectionSet = res.Value
Dim idarray As ObjectId() = SS.GetObjectIds()

Dim db As Database = Application.DocumentManager.MdiActiveDocument.Database
Dim tm As Autodesk.AutoCAD.DatabaseServices.TransactionManager = db.TransactionManager

Dim myT As Transaction = tm.StartTransaction()
Try
Dim id As ObjectId
For Each id In idarray
Dim ent As Entity = tm.GetObject(id, OpenMode.ForWrite, True)
Dim Sched As New AecScheduleApplication
Dim PropSets As AecSchedulePropertySets
Dim propSet As AecSchedulePropertySet
Dim i As Integer
PropSets = Sched.PropertySets(ent)
For i = 0 To PropSets.Count - 1
propSet = PropSets.Item(i)
If propSet.Name = "3-NZS3604Joists" Then
ed.WriteMessage((ControlChars.Lf + "You selected: " + propSet.Name))
Else
ed.WriteMessage((ControlChars.Lf + "You selected 2: " + propSet.Name))
End If
Next
Next id
Finally
myT.Dispose()
End Try
End Sub 'singlePick
End Class 'AcEdSSGetCommand
End Namespace 'Selection

I think i am almost there 🙂
0 Likes
Message 4 of 4

Anonymous
Not applicable
I think the problem is that you're mixing the
managed and COM APIs.

In the line:

PropSets = Sched.PropertySets(ent);

The 'ent' parameter is a managed object, which
you're passing to a COM object. The COM object
doesn't know what a managed object is.

Try:

PropSets = Sched.PropertySets(ent.AcadObject);

Managed and COM apis are not interoperable,
so you can't pass managed objects to COM
APIs or visa verse. The AcadObject property of
the managed wrapper for an entity, is its COM
wrapper. You can go the other way (e.g., from
the COM wrapper to the managed wrapper) with
the DBObject.FromAcadObject() method.

Always investigate to see if there is a managed
API that can do what a COM API does, and try to
use the managed API if available.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com

wrote in message news:5780672@discussion.autodesk.com...
Thank you for your reply,

I think my issue is the way im getting the aec object from the using input. I get the following error when i run the below code, "Unable to cast object of type 'Autodesk Aec.Structural.DatabaseServices.Member' to type 'Autodesk.AutoCAD.Interop.Common.AcadObject'

Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.EditorInput

Imports Autodesk.AutoCAD.Interop
Imports Autodesk.AutoCAD.Interop.Common
Imports Autodesk.AEC.Interop.Schedule
Imports Autodesk.AEC.Interop.ArchBase

Namespace Selection

Public Class AcEdSSGetCommand

Shared SelentityCount As Integer = 0
Shared UseThisSelectionResult As PromptSelectionResult
Shared UseThisSelectionOption As PromptSelectionOptions = Nothing

'This command allows only a single entity to be picked
_
Public Sub singlePick()
Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
Dim Opts As New PromptSelectionOptions()
Opts.AllowDuplicates = True
Opts.MessageForAdding = "Select entities"
Dim res As PromptSelectionResult = ed.GetSelection(Opts)

If res.Status = PromptStatus.Error Then
Return
End If

Dim SS As Autodesk.AutoCAD.EditorInput.SelectionSet = res.Value
Dim idarray As ObjectId() = SS.GetObjectIds()

Dim db As Database = Application.DocumentManager.MdiActiveDocument.Database
Dim tm As Autodesk.AutoCAD.DatabaseServices.TransactionManager = db.TransactionManager

Dim myT As Transaction = tm.StartTransaction()
Try
Dim id As ObjectId
For Each id In idarray
Dim ent As Entity = tm.GetObject(id, OpenMode.ForWrite, True)
Dim Sched As New AecScheduleApplication
Dim PropSets As AecSchedulePropertySets
Dim propSet As AecSchedulePropertySet
Dim i As Integer
PropSets = Sched.PropertySets(ent)
For i = 0 To PropSets.Count - 1
propSet = PropSets.Item(i)
If propSet.Name = "3-NZS3604Joists" Then
ed.WriteMessage((ControlChars.Lf + "You selected: " + propSet.Name))
Else
ed.WriteMessage((ControlChars.Lf + "You selected 2: " + propSet.Name))
End If
Next
Next id
Finally
myT.Dispose()
End Try
End Sub 'singlePick
End Class 'AcEdSSGetCommand
End Namespace 'Selection

I think i am almost there 🙂
0 Likes