Message 1 of 5
Tried to display block attributes when block is selected on palette

Not applicable
03-30-2016
06:32 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
My code:
View: Xaml code
<UserControl x:Class="View_ATT" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:SchneiderMacros" mc:Ignorable="d" d:DesignHeight="230" d:DesignWidth="325"> <Grid Background="#FF007ACC"> <StackPanel Margin="5 " Background="#FF252526" > <StackPanel Orientation="Horizontal" > <TextBlock x:Name="Block" Width=" 30" Margin=" 5" Text="Block " Foreground="#FFE6E6EE" FontWeight="Bold" TextDecorations="{x:Null}"/> <StackPanel > <TextBlock x:Name="txtBlkName" Width=" 150" Margin=" 2" Foreground="#FFEAEAF3" Text="{Binding blkname,Mode=TwoWay,NotifyOnSourceUpdated=True}"></TextBlock> <TextBlock x:Name="txtblkBLKID" Width=" 150" Margin=" 2" Foreground="#FFDADAE4" Text="{Binding blockid,Mode=TwoWay,NotifyOnSourceUpdated=True}"></TextBlock> </StackPanel> <Button x:Name="GetAtt" Width="85" Margin=" 2" Content="Get Attributes"></Button> <Image Source="S:\Transfer\Pankaj_Potdar\acadplugin\unnamed.png" Height="28" Width="28" /> </StackPanel> <StackPanel Orientation="Horizontal" Margin=" 5"> <StackPanel Margin=" 2" HorizontalAlignment="Left" Width="140"> <TextBlock x:Name="tagDL" Margin="2 " Height=" 20" Text="{Binding tagDL,Mode=TwoWay,NotifyOnSourceUpdated=True}" Foreground="#FFD1D1E2" ></TextBlock> <TextBlock x:Name="tagDN" Margin=" 2" Height=" 20" Text="{Binding tagDN,Mode=TwoWay,NotifyOnSourceUpdated=True}" Foreground="#FFD1D1E2"></TextBlock> <TextBlock x:Name="tagSQDPN" Margin=" 2" Height=" 20" Text="{Binding tagsqdpn,Mode=TwoWay,NotifyOnSourceUpdated=True}" Foreground="#FFD1D1E2"></TextBlock> <TextBlock x:Name="tagMODEL" Margin=" 2" Height=" 20" Text="{Binding tagmodel,Mode=TwoWay,NotifyOnSourceUpdated=True}" Foreground="#FFD1D1E2"></TextBlock> <TextBlock x:Name="tagMANUFACTURER" Margin=" 2" Height=" 20" Text="{Binding tagmanufacturer,Mode=TwoWay,NotifyOnSourceUpdated=True}" Foreground="#FFD1D1E2"></TextBlock> </StackPanel> <StackPanel Margin=" 2" HorizontalAlignment="Right" Width="140"> <TextBox x:Name="txtboxDL" Margin="2 " Height=" 20" Text="{Binding devicelocation,Mode=TwoWay,NotifyOnSourceUpdated=True}"/> <TextBox x:Name="txtboxDN" Margin="2 " Height=" 20" Text="{Binding devicename,Mode=TwoWay,NotifyOnSourceUpdated=True}"/> <TextBox x:Name="txtboxSQDPN" Margin="2 " Height=" 20" Text="{Binding sqdpn,Mode=TwoWay,NotifyOnSourceUpdated=True}"/> <TextBox x:Name="txtboxMODEL" Margin="2 " Height=" 20" Text="{Binding model,Mode=TwoWay,NotifyOnSourceUpdated=True}"/> <TextBox x:Name="txtboxMANUFACTURER" Margin="2 " Height=" 20" Text="{Binding manufacturer,Mode=TwoWay,NotifyOnSourceUpdated=True}"/> </StackPanel> <StackPanel Margin=" 0"> <CheckBox x:Name="sqdpnhdn" Margin="0,55,0,0" HorizontalAlignment="Center" IsChecked="{Binding hidden, Mode=TwoWay, NotifyOnSourceUpdated=True}"/> </StackPanel> </StackPanel> <StackPanel Orientation="Horizontal" > <Button x:Name="btnUpdate" Width="50 " Height=" 25" Margin=" 10" HorizontalAlignment="Left" Content="Update "></Button> <Image Source="S:\Transfer\Pankaj_Potdar\acadplugin\Schneider-Electric_White.png" Height="45" Width="68" Margin=" 170,0,0,0" Stretch="Fill"/> </StackPanel> </StackPanel> </Grid> </UserControl>
My Model
Imports System.Drawing Imports System.Windows.Forms Imports System.Windows.Forms.Integration Public Class GetATT_Model Public DL As String Public tagDL As String Public DN As String Public tagDN As String Public SQDPN As String Public tagSQDPN As String Public MODEL As String Public tagMODEL As String Public MANUFACTURER As String Public tagMANUFACTURER As String Public blkname As String Public blockID As String Public hiddden As Boolean Public Function findatt(objectid() As ObjectId) Dim device As New GetATT_Model Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument Dim db As Database = doc.Database Dim ed As Editor = doc.Editor If objectid.Length = 1 Then Using tr As Transaction = doc.TransactionManager.StartTransaction Dim cmd As String = "CANCELCOMMANDVBNET" & vbCr doc.SendStringToExecute(cmd, True, False, False) Dim blkref As BlockReference = tr.GetObject(objectid(0), OpenMode.ForRead) Dim ext As Extents3d Dim ent As Entity = tr.GetObject(objectid(0), OpenMode.ForRead) ext = ent.GeometricExtents device.blkname = blkref.Name device.blockID = blkref.ObjectId.ToString Dim attcol As Autodesk.AutoCAD.DatabaseServices.AttributeCollection = blkref.AttributeCollection For Each attid As ObjectId In attcol Dim attref As AttributeReference = tr.GetObject(attid, OpenMode.ForRead) Select Case attref.Tag.ToString Case "DEVICE_LOCATION" device.DL = attref.TextString.ToString device.tagDL = attref.Tag.ToString Case "DEVICE_NAME" device.DN = attref.TextString.ToString device.tagDN = attref.Tag.ToString Case "SQD_PN" device.SQDPN = attref.TextString.ToString device.tagSQDPN = attref.Tag.ToString If attref.Layer = "SQD_PN" Then device.hiddden = False Else device.hiddden = True End If Case "MODEL" device.MODEL = attref.TextString.ToString device.tagMODEL = attref.Tag.ToString Case "MANUFACTURER" device.MANUFACTURER = attref.TextString.ToString device.tagMANUFACTURER = attref.Tag.ToString End Select Next ext.TransformBy(ed.CurrentUserCoordinateSystem.Inverse()) zoomwin(ed, ext.MinPoint, ext.MaxPoint) tr.Commit() End Using Else MsgBox("Select only one block", MsgBoxStyle.Critical) End If Return device End Function Public Sub zoomwin(ed As Editor, min As Point3d, max As Point3d) Dim min2d As Point2d = New Point2d(min.X, min.Y) Dim max2d As Point2d = New Point2d(max.X, max.Y) Dim view As ViewTableRecord = New ViewTableRecord view.CenterPoint = min2d + ((max2d - min2d) / 2) view.Height = max2d.Y - min2d.Y view.Width = max2d.X - min2d.X ed.SetCurrentView(view) End Sub End Class
Xaml.vb code
Public Class View_ATT Public viewmodel As New GetATT_ViewModel Sub New() ' This call is required by the designer. InitializeComponent() Me.DataContext = viewmodel ' Add any initialization after the InitializeComponent() call. End Sub Public Sub testit(sender As Object, e As SelectionAddedEventArgs) Dim objectid() As ObjectId = e.AddedObjects.GetObjectIds viewmodel.getattribute(objectid) End Sub End Class