Tried to display block attributes when block is selected on palette

Tried to display block attributes when block is selected on palette

Anonymous
Not applicable
584 Views
4 Replies
Message 1 of 5

Tried to display block attributes when block is selected on palette

Anonymous
Not applicable

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

 

 

0 Likes
585 Views
4 Replies
Replies (4)
Message 2 of 5

norman.yuan
Mentor
Mentor

What purpose you post the code for? Any question? 

 

Without knowing what issue you may have, one thing is immediately caught in my eyes: why do you call Document.SebdStringToExecute() to call a command "CANCELCOMMANDVBNET" during a Transaction. No matter what that command does, it is bad thing to call SendStringToExecute() during a Transaction.

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 3 of 5

Anonymous
Not applicable

@norman.yuan First of all thanks for reply.

 

Question is I want to display block attributes on palette whenever user selects block, I added ed.selectionadded event for that.

everything is good but textbox does not show anything.

 

Command you were talking about is for cancelling selection, I am new programmer , I will try to remove that from within transaction.

 

Thanks,

Pankaj

0 Likes
Message 4 of 5

_gile
Consultant
Consultant

Hi,

 

To cancel a selection, you'd rather use the Editor.SetImpliedSelection() method passing it a null or empty ObjectId array.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 5 of 5

Anonymous
Not applicable

@_gile thanks for reply it helped.

 

I am facing another problem now I added ed.selectionadded event handler but I am not able to remove it.

I posted below problem in different post but in case if yu can help!

 

I am using below eventhandler to add e.selectionadded event

 

 

 

AddHandler ed.SelectionAdded, AddressOf testit

 

 

And I am using below statement to remove it.

 

 

RemoveHandler ed.SelectionAdded, AddressOf testit

 

 

 

But it does not get removed.

 

My testit function,

 

 

Public viewmodel As New GetATT_ViewModel
 Public Sub testit(sender As Object, e As SelectionAddedEventArgs)
        Dim objectid() As ObjectId = e.AddedObjects.GetObjectIds

        viewmodel.getattribute(objectid)


    End Sub

 

I read somewhere that you need to make function shared but I can not make that as I am calling another function in it which is not shared.

0 Likes