Author Topic: draw order using just interop .. sortents dictionary  (Read 3385 times)

0 Members and 1 Guest are viewing this topic.

zeppeldep

  • Guest
draw order using just interop .. sortents dictionary
« on: July 19, 2012, 10:43:48 AM »
greetings swamp folk... I am need of a little help..
current circumstance has forced me to resort to stand alone development.. I no longer have the luxury of the extended managed dot net api within acad.
I am using the COM with C# 2010, developing for use in version 2012 of acad.
Things were going great, completed many functions.. then today happened.. I lost my stride.. now I need swamp talent to get me out of trouble. The latest function needs draw order change (sort ents). I am lost, do not know where to start! I found acadsorttable .. but I dont know how to use it in code to put an entity below another entity.
Please help...
Thx.
Kevin.

fixo

  • Guest
Re: draw order using just interop .. sortents dictionary
« Reply #1 on: July 19, 2012, 11:41:54 AM »
Welcome on board, zeppeldep !
See if this helps, but change file name within the code
Code: [Select]
        <CommandMethod("drw")> _
    Public Sub TestDrawOrder()
        Dim acadapp As AcadApplication = New AcadApplication
        acadapp.Visible = True
        acadapp.WindowState = AcWindowState.acMax
        acadapp.Eval("msgbox(""Wait..."")")
        ' change file name
        Dim acdoc As AcadDocument = acadapp.Documents.Open("C:\Test\zzz.dwg", Nothing, Nothing)
        Dim pickPt As Object = Nothing
        Dim obj As Object = Nothing
        Dim util As AcadUtility = acadapp.ActiveDocument.Utility

        util.GetEntity(obj, pickPt, vbLf & "Select entity to move to top: ")

        Dim sortObj As AcadObject = Nothing

        Try
            'Get an extension dictionary and, if necessary, add a SortentsTable object
            Dim xdict As AcadDictionary
            xdict = acdoc.ModelSpace.GetExtensionDictionary

            ' bypass if GetObject failed
            Try

                sortObj = xdict.GetObject("ACAD_SORTENTS")

            Catch

                sortObj = xdict.AddObject("ACAD_SORTENTS", "AcDbSortentsTable")

            End Try

            '' util.Prompt(String.Format(vbLf & "Dict Name: {0}", sortObj.ObjectName))
            Dim ObjIds(0) As Long
            ObjIds(0) = obj.ObjectID
           
            Dim varObject As AcadObject
            varObject = acdoc.ObjectIdToObject(ObjIds(0))

            Dim arr(0) As AcadObject
            arr(0) = varObject
            ''  util.Prompt(String.Format(vbLf & "Obj Name: {0}", varObject.ObjectName))
            'set draworder to the top
            sortObj.MoveToBottom(arr)

            acdoc.Regen(AcRegenType.acActiveViewport)

            acadapp.Update()
        Catch
        End Try
        '' comment this block if it's needs:
        acadapp.ActiveDocument.SaveAs(acadapp.ActiveDocument.FullName, Autodesk.AutoCAD.Interop.Common.AcSaveAsType.ac2007_dwg, Nothing)
        acadapp.ActiveDocument.Close(True, Nothing)
        acadapp.Quit()
        acadapp = Nothing
    End Sub

~'J'~
« Last Edit: July 20, 2012, 02:18:39 AM by fixo »

zeppeldep

  • Guest
Re: draw order using just interop .. sortents dictionary
« Reply #2 on: July 19, 2012, 12:00:06 PM »
that looks like it.. u saved me again... I will test it tomoro at the office... The Swamp ROCKS! Fixo is the main dude.. thanx a stack ..

zeppeldep

  • Guest
Re: draw order using just interop .. sortents dictionary
« Reply #3 on: July 20, 2012, 12:25:14 AM »
I have a missing reference.. ?
... MoveToTop method is not available beneath the SortObj object..?
referenced ..
AutoCAD ... AutoCAD 2012 Type Library ... Autodesk.AutoCAD.Interop ... and
AXDBLib ... AutoCAD/ObjectDBX Common 18.0 Type Library ... Autodesk.AutoCAD.Interop.Common

can I reference more 'items' to make the MoveToTop method available?

thx for your patience ...
Kevin.

fixo

  • Guest
Re: draw order using just interop .. sortents dictionary
« Reply #4 on: July 20, 2012, 02:00:12 AM »
Kevin, try again the code above

~'J'~
« Last Edit: July 20, 2012, 02:19:30 AM by fixo »

zeppeldep

  • Guest
Re: draw order using just interop .. sortents dictionary
« Reply #5 on: July 20, 2012, 02:48:21 AM »
still not.. I think I am missing a reference.. I manage to create/get the sort table object but the resulting object does not include draw order methods .. like movetotop etc...
The project is referring to two COMs .. AutoCAD and AXDBLib ..
then uses..
System.Runtime.interopservices
autodesk.autocad.interop
autodesk.autocad.interop.common

I think I need another reference to get access to draw order methods ..  ???

fixo

  • Guest
Re: draw order using just interop .. sortents dictionary
« Reply #6 on: July 20, 2012, 03:13:47 AM »
Think I need to digg deeper in this case, see private message

~'J'~

MexicanCustard

  • Swamp Rat
  • Posts: 705
Re: draw order using just interop .. sortents dictionary
« Reply #7 on: July 20, 2012, 07:11:52 AM »
I'm lost following what you guys are trying to do.  Anytime I want to manipulate the draw order I use the DrawOrderTable in modelspace.  Is there a reason you're going straight to the extension dictionary?
Revit 2019, AMEP 2019 64bit Win 10

fixo

  • Guest
Re: draw order using just interop .. sortents dictionary
« Reply #8 on: July 20, 2012, 09:24:24 AM »
Interop have not have the 'DrawOrderTable' object,
I've used 'AcDbSortensTable.MoveToTop' method instead

~'J'~

zeppeldep

  • Guest
Re: draw order using just interop .. sortents dictionary
« Reply #9 on: July 20, 2012, 11:00:19 AM »
Fixo got it right.. needed to include the definition before the variable .. amazing .. IDE was saying.. missing assembly.. just needed to get the format right , like the following...
THX FIXO

             ( (AcadSortentsTable) SortObj).MoveToTop(objs);

fixo

  • Guest
Re: draw order using just interop .. sortents dictionary
« Reply #10 on: July 20, 2012, 02:43:55 PM »
I like to help if this is usefull for you,
Still continue to do work further,
Cheers :)