.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Inserting a MvPart into Autocad MEP

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
Keith.Brown
709 Views, 4 Replies

Inserting a MvPart into Autocad MEP

I finally took the plunge into customizing Autocad MEP with dotnet and right away I am running into a situation.  I am trying to use code to insert specific equipment into a drawing without sorting thru the out of the box interface or clunky command line functions.  I am using the part guid and the part size name to choose specific equipment but it always seems to insert the first part associated with the guid.  For example if I have several vav boxes in a part.  The part guid is the same for all but the part size name is different.  When I use the code below it always inserts the first part in the list.  It seems to ignore the partsize name.

        <CommandMethod("addTitusDESV04-WC-1-LH")> _
        Public Sub AddTitusDesv04wc1lh()

            Addequipment("8AC91934-10D6-4743-BEB2-747CD6630AAE", "Titus DESV04-WC1-LH")

        End Sub

        Public Sub Addequipment(ByVal pguid As String, ByVal pname As String)

            Dim mEditor As Editor
            Dim mDb As Database
            Dim mTransMgr As Autodesk.AutoCAD.DatabaseServices.TransactionManager

            mEditor = Application.DocumentManager.MdiActiveDocument.Editor
            mDb = Application.DocumentManager.MdiActiveDocument.Database
            mTransMgr = Application.DocumentManager.MdiActiveDocument.TransactionManager

            Dim mTrans As Transaction = mTransMgr.StartTransaction

            Try
                ' get the query object
                Dim query As New DataQuery
                query.Domain = Domain.MultiViewPartComponent
                query.PartGuid = pguid
                query.PartName = pname

                Dim exTbl As DataExpandedTable = PartManager.GetPartTable(query, 100)
                ' create the new mvpart
                Dim mvPart As New MultiViewPart()
                mvPart.SetDatabaseDefaults()
                mvPart.SetToStandard(mDb)
                PartManager.CreatePartViaRecord(exTbl, exTbl.DataRecords(0), mvPart)

                Dim ppr As PromptPointResult = mEditor.GetPoint("" & Chr(10) & "Specify insert point: ")
                If ppr.Status <> PromptStatus.OK Then
                    Return
                End If
                ' assign selected point
                mvPart.Location = ppr.Value
                ' set the layer
                mvPart.SetDefaultLayer()

                ' finally we will add the part to the database and commit the transaction
                Dim bt As BlockTable = DirectCast(mTransMgr.GetObject(mDb.BlockTableId, OpenMode.ForWrite, False), BlockTable)
                Dim btr As BlockTableRecord = DirectCast(mTransMgr.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite, False), BlockTableRecord)
                btr.AppendEntity(mvPart)
                mTransMgr.AddNewlyCreatedDBObject(mvPart, True)

            Catch ex As System.Exception
                mEditor.WriteMessage(ex.Message)
            Finally
                mTrans.Commit()
            End Try


        End Sub

 

Am i wrong in assuming that query.partname is the partsizename?  Also I know that I am inserting the first item in the record by using the code

 

PartManager.CreatePartViaRecord(exTbl, exTbl.DataRecords(0), mvPart)

 

but I was assuming that by using the partsize name i was restricting the list of parts to one.  Obviously this is incorrect.

 

What I am trying to do is insert a specific part without any interaction from the user.  I want them to either a) type a command to insert the part or b) use a ribbon control to insert the part.  Is this possible?  Thanks for any help you might be able to give.

4 REPLIES 4
Message 2 of 5
Keith.Brown
in reply to: Keith.Brown

Ok,  I was able to get this to work as expected by changing the line

 

query.PartName = pname

 

to

 

query.AddSizeParameter(Context.CatalogPartSizeName, 0, pname)

 

This allows me to insert specific parts into the database without user interaction other than starting the command.

 

Next question, does anyone know how to show a preview of the part as it is being inserted?

 

Also, I would like to call the AddEquipment(pguid, pname) from a button on a palette but when i call the procedure from the button clicked event it doesnt recognize the procedure name.  Is this because the procedure is in a seperate class from the userform that the button belongs to?  If so, how can i get the button on the userform to recognize the procedure from a different class?  Sorry if that is a noob question but I really just started learning vb.net yesterday.  Thanks in advance.

 

 

Message 3 of 5
arcticad
in reply to: Keith.Brown

You will need to add the "shared" keyword to the sub

 

Public Class Class1
    Shared Sub thisIsMyProgram()
    End Sub
End Class

 

then when you call the function use the full name.

 

Class1.thisIsMyProgram()

 

 

 

 

 

---------------------------



(defun botsbuildbots() (botsbuildbots))
Message 4 of 5
Keith.Brown
in reply to: arcticad

I have tried this but when i try to call the sub from the button click event i get the following error from the compilier.

 

Error 1 'AddEquipment' is not a member of 'Autocad_Test_Project.myCommands'

 

 

which is clearly wrong because the sub works as expected when called from inside the class per my code in the original post.

Message 5 of 5
Keith.Brown
in reply to: Keith.Brown

Finally got it to work but had to use the following format:

 

namespace.Class1.thisIsMyProgram()

 

Thanks for your help.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost