• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    .NET

    Reply
    Active Member
    Posts: 9
    Registered: ‎11-12-2012
    Accepted Solution

    Select block reference by attribute value

    326 Views, 6 Replies
    11-29-2012 10:43 AM

    I have a drawing with many block references on it and they have some attributes.

    I know how to find the block reference witch the attribute value, and even change it but I don't know how to select it once I have the object ID of the block.

    How can I do the selection without asking the user to select it?

     

    thanks.

     

    Please use plain text.
    Distinguished Contributor
    khoa.ho
    Posts: 131
    Registered: ‎09-15-2011

    Re: Select block reference by attribute value

    11-29-2012 11:28 AM in reply to: maiterela

    Hi,

     

    Once you have the ObjectId of an entity (block, line, circle...), use Editor.SetImpliedSelection() method to select this entity on the screen (the entity will be highlighted with grips) without asking the user to manually select it. The following code snippet will help:

     

    Application.DocumentManager.MdiActiveDocument.Editor.SetImpliedSelection(new ObjectId[] { entity.ObjectId });

     

    -Khoa

     

    Please use plain text.
    Active Member
    Posts: 9
    Registered: ‎11-12-2012

    Re: Select block reference by attribute value

    11-29-2012 11:33 AM in reply to: maiterela

    Thanks for your soon answer. I will try tomorrow.

    One more question.

    How can I punt this selected object in the clipboard?

    What I really want to do is to copy it and then "paste" in my tool palette.

     

    Thanks

    Maitere

    Please use plain text.
    Distinguished Contributor
    khoa.ho
    Posts: 131
    Registered: ‎09-15-2011

    Re: Select block reference by attribute value

    11-29-2012 10:49 PM in reply to: maiterela

    Hi Maitere,

     

    Here is the code to copy an entity (specified by ObjectId) to the clipboard. I don't know how to paste it to a given tool palette yet.

     

    public static void CopyEntityToClipboard(ObjectId objectId)
    {
        Document doc = Application.DocumentManager.MdiActiveDocument;
        Editor editor = doc.Editor;
        using (doc.LockDocument())
        {
            editor.SetImpliedSelection(new ObjectId[] { objectId });
            doc.SendStringToExecute("_copyclip ", true, false, true);
        }
    }
    
    // Testing method
    [CommandMethod("CopyEntityToClipboard")] public static void CopyEntityToClipboard() { Document doc = Application.DocumentManager.MdiActiveDocument; Editor editor = doc.Editor; PromptEntityResult entityResult = editor.GetEntity("Select an entity:"); if (entityResult.Status == PromptStatus.OK) { CopyEntityToClipboard(entityResult.ObjectId); } }

     

    We can also use ToolPaletteManager and CustomToolBase classes to create a new palette, then add custom commands to this palette. Lookup Kean's code to see how to do it. But adding a block to the palette using API requires lots of work.

     

    -Khoa

     

    Please use plain text.
    Active Member
    Posts: 9
    Registered: ‎11-12-2012

    Re: Select block reference by attribute value

    12-01-2012 02:31 AM in reply to: maiterela

    We have get to put a block in a tool palette using the tips you have done.

    The steps we have follow are:

    1. Find the block and get de ObjectID

    2. Select the block

    3. Copy to clipboard

    4. Find the tool palette by name

    5. Paste the content of the clipboard.

     

    We have had some problems using .NET  SendStringToExecute and copy and paste commands needed to be execute sincronously, that is way whe hace user COM SendCommand instead.

     

    To do the PASTE we have done an ObjectARX function, perhaps there is a easier way to do this.

    Here you are the code, beginins one we have the Block Object ID.

     

    Thanks

    Maitere

     

    Public Shared Sub AddBlockReferenceToPalette2 _
    ( _
    ByVal nombrePaleta As String, _
    ByVal brefObjectId As ObjectId, ByRef docBloque As Document _
    )

    'Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
    'Dim doc As Document = Application.DocumentManager.MdiActiveDocument

    Dim ed As Editor = docBloque.Editor
    Dim doc As Document = docBloque

    If Not brefObjectId.IsNull Then

    ' Se busca la paleta
    Dim ps As System.IntPtr = AcTcUiGetToolPaletteWindow()
    Dim pal As System.IntPtr = CAcTcUiToolPaletteSet_FindPalette(ps, nombrePaleta, System.IntPtr.Zero, False)
    If pal <> System.IntPtr.Zero Then


    ed.SetImpliedSelection(New ObjectId() {brefObjectId})


    'Copiar bloque a portapapeles
    'doc.SendStringToExecute("_copyclip ", True, False, True)
    ' MAITERE
    ' Se usa SendCommand de COM para que lo haga de forma inmediata, sino .NET lo hace de forma asincrona
    Dim app As Autodesk.AutoCAD.Interop.AcadApplication = Application.AcadApplication
    app.ActiveDocument.SendCommand("_copyclip ")

     

    ' Se copia el bloque a la paleta-> se llama a un comando de ARX
    'doc.SendStringToExecute("PegarBloquePaleta " + nombrePaleta + Chr(13), True, False, False)
    ' MAITERE
    ' Se usa SendCommand de COM para que lo haga de forma inmediata, sino .NET lo hace de forma asincrona
    app.ActiveDocument.SendCommand("PasteBloquePaleta " + nombrePaleta + Chr(13))

    End If
    End If
    End Sub


    ' To paste de selection block we have put in the clipboard we have done a ObjectARX Function.

    void PasteBloquePaleta()
    {
    TCHAR nombrePaleta[1000];
    int res;

    res = acedGetString (1, _T("\nPaleta de destino: "), nombrePaleta);

    CAcTcUiToolPaletteSet* ps = AcTcUiGetToolPaletteWindow();
    CAcTcUiToolPalette* pal = ps->FindPalette(nombrePaleta, NULL, FALSE);
    if (pal == NULL)
    return;

    IDataObject* pdo;
    if (SUCCEEDED(::smileysurprised:leGetClipboard(&pdo)))
    {
    if (pal->Paste(pdo, 0, NULL))
    {
    pal->S
    // success
    }

    }

    }

     

    Please use plain text.
    Distinguished Contributor
    khoa.ho
    Posts: 131
    Registered: ‎09-15-2011

    Re: Select block reference by attribute value

    12-01-2012 10:31 AM in reply to: maiterela

    It's very interesting that you can make it work with the combination of .NET, COM and ObjectARX. I hope you may see the blog from Adam Nagy. He presents the code to add a block reference to a specified tool palette using either ObjectARX or .NET with imported P/Invoke methods from AcTcUi.dll

     

    -Khoa

     

    Please use plain text.
    Active Member
    Posts: 9
    Registered: ‎11-12-2012

    Re: Select block reference by attribute value

    12-02-2012 02:28 AM in reply to: maiterela

    Yes, we have used the information of the article "Add block reference to a tool palette".

     

     

    Please use plain text.