.NET

Reply
Contributor
nijhuis
Posts: 16
Registered: ‎09-26-2010
Message 1 of 5 (304 Views)
Accepted Solution

transparancy viewportoverride

304 Views, 4 Replies
02-10-2012 04:54 AM

Hi,

 

Does anyone how to make a layer or an entity transparant within a viewport?

 

I figured out the following code found in:

http://through-the-interface.typepad.com/through_the_interface/2010/06/creating-transparent-hatches-...

 

It gives an error at New Autodesk.AutoCAD.Colors.Transparency(127)

 

 

 

Using transactie AsTransaction = DWG.TransactionManager.StartTransaction

 

Dim Layertable AsLayerTable = DWG.LayerTableId.GetObject(OpenMode.ForRead)

 

Dim VP AsViewport = transactie.GetObject(Doc.Editor.CurrentViewportObjectId, OpenMode.ForWrite)

 

Dim LVPO AsLayerViewportProperties

 

ForEach LayerID In Layertable

 

Dim LaagTabelRec AsLayerTableRecord = transactie.GetObject(LayerID, OpenMode.ForRead)

 

LVPO = LaagTabelRec.GetViewportOverrides(VP.Id)

LVPO.Transparency = New Autodesk.AutoCAD.Colors.Transparency(127)

 

Next

transactie.Commit()

EndUsing

 

I use autocad 2011 64bit with visual studio 2008.

 

i tried Cbyte(127) and that did the trick!

 

thanks!

*Expert Elite*
Alfred.NESWADBA
Posts: 9,396
Registered: ‎06-29-2007
Message 2 of 5 (286 Views)

Re: transparancy viewportoverride

02-12-2012 12:20 PM in reply to: nijhuis

Hi,

 

I used the following code and for me it does not interrupt at the line for setting the layer-override-transparency ..... as long as I have a layout active and I'm IN a viewport :smileywink:

Of course it crashes if I have the tab "Model Space" active (so I don't have a layout active)

 

   <Runtime.CommandMethod("ADESK_VPLayerTransparency")> _
   Public Shared Sub ADESK_VPLayerTransparency()
      Dim tDwg As ApplicationServices.Document = ApplicationServices.Application.DocumentManager.MdiActiveDocument
      Dim tDwgLock As ApplicationServices.DocumentLock = Nothing
      Try
         tDwgLock = tDwg.LockDocument
         Using transactie As DatabaseServices.Transaction = tDwg.TransactionManager.StartTransaction

            Dim Layertable As DatabaseServices.LayerTable = CType(transactie.GetObject(tDwg.Database.LayerTableId, DatabaseServices.OpenMode.ForRead), DatabaseServices.LayerTable)
            Dim LVPO As DatabaseServices.LayerViewportProperties

            For Each LayerID As DatabaseServices.ObjectId In Layertable
               Dim LaagTabelRec As DatabaseServices.LayerTableRecord = CType(transactie.GetObject(LayerID, DatabaseServices.OpenMode.ForWrite), DatabaseServices.LayerTableRecord)
               LVPO = LaagTabelRec.GetViewportOverrides(tDwg.Editor.CurrentViewportObjectId)
               LVPO.Transparency = New Autodesk.AutoCAD.Colors.Transparency(127)
            Next

            transactie.Commit()
         End Using
      Catch ex As Exception
         Call MsgBox("Unknown error in 'ADESK_VPLayerTransparency'" & vbNewLine & ex.Message)
      Finally
         If tDwgLock IsNot Nothing Then tDwgLock.Dispose() : tDwgLock = Nothing
      End Try
   End Sub

 

HTH, - alfred -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Contributor
nijhuis
Posts: 16
Registered: ‎09-26-2010
Message 3 of 5 (280 Views)

Re: transparancy viewportoverride

02-13-2012 12:08 AM in reply to: nijhuis

Thanks for your reply.

When i use new ...colors.transparency(127)  visual studio gives me an error. (see attachement 1)

 

i tried to replace 127 with an byte-value and visual studio gives me another error. (see attachement 2)

*Expert Elite*
Alfred.NESWADBA
Posts: 9,396
Registered: ‎06-29-2007
Message 4 of 5 (274 Views)

Re: transparancy viewportoverride

02-13-2012 12:33 AM in reply to: nijhuis

Hi,

 

what version of AutoCAD do you use? I tried it with 2012(64bit) and Option Strict ON, and I don't get a message, neither during code-writing nor during runtime.

Could you try:

LVPO.Transparency = New Autodesk.AutoCAD.Colors.Transparency(CByte(127))

 

- alfred -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Contributor
nijhuis
Posts: 16
Registered: ‎09-26-2010
Message 5 of 5 (273 Views)

Re: transparancy viewportoverride

02-13-2012 12:38 AM in reply to: nijhuis

I use autocad 2011 64bit with visual studio 2008.

 

i tried Cbyte(127) and that did the trick!

 

thanks!

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!