.NET

Reply
Mentor
khoa.ho
Posts: 224
Registered: ‎09-15-2011
Message 11 of 26 (348 Views)

Re: plugin problem in vb .net

08-23-2012 11:08 PM in reply to: khoa.ho

I rewrote your code to make it more logical and understandable to read. There is only one class ClientServerPlugin for both client and server. The problem is that the code is not completed for the client side to send DWG file to the server. So there is nothing to render on the server then it causes error on RenderToImage() method. Before going further to fix, there are some questions to clarify:

1. What is the purpose for this server-client project? Do we need one server and many clients connected? By that way, the server will work asynchronously to listen for requests from many clients. We assume one client is one AutoCAD instance in one user machine.

2. Each client sends its drawing with 3D objects to render. The server will take it and render to an image (PNG format), save it to a network drive, and return WHAT to the client? It is quite confusing that the client then generates a result DWG file but what's inside this file?

For testing, we need to open two AutoCAD, one (server side) types "StartServer" command, then another (client side) types "RenderOnServer" command. But the image is not saved yet. It will get fixed later.

I get to sleep now. The following is my new refactoring code:

''' <summary>
''' Wrapper for clients in queue
''' </summary>
Public Structure ClientWrapper
	Public Property TcpClient() As TcpClient
		Get
			Return m_TcpClient
		End Get
		Set
			m_TcpClient = Value
		End Set
	End Property
	Private m_TcpClient As TcpClient
	Public Property File() As MemoryStream
		Get
			Return m_File
		End Get
		Set
			m_File = Value
		End Set
	End Property
	Private m_File As MemoryStream
	Public Property Result() As FileStream
		Get
			Return m_Result
		End Get
		Set
			m_Result = Value
		End Set
	End Property
	Private m_Result As FileStream
End Structure

''' <summary>
''' Client server plugin
''' </summary>
Public Class ClientServerPlugin
	Private Const IpServer As String = "127.0.0.1"
	Private Const PortNum As Integer = 8000
	Private Const PacketSize As Integer = 4096
	Private Const SavedDirectory As String = "C:\\RenderPluginACD\\"
	Private _client As ClientWrapper
	' Queue that holds clients and their files
	Private ReadOnly _editor As Editor = Application.DocumentManager.MdiActiveDocument.Editor
	Private _tcpClient As System.Net.Sockets.TcpClient

	#Region "ClientPlugin"
	<CommandMethod("RenderOnServer")> _
	Public Sub SendToRenderer()
		Connect()
		Dim inputFileName As String = "MyDrawing.dwg"
		Dim outputFileName As String = "Return.dwg"
		Save(inputFileName)
		Send(inputFileName)
		ReceivePhoto(outputFileName)
		Disconnect()
	End Sub

	Private Sub Connect()
		_tcpClient = New System.Net.Sockets.TcpClient()
		_tcpClient.Connect(IpServer, PortNum)
	End Sub

	Private Sub Disconnect()
		' Shutdown and end connection
		_tcpClient.Close()
	End Sub

	''' <summary>
	''' Save the current drawing to a file
	''' </summary>
	''' <param name="fileName">file name to save</param>
	Private Sub Save(fileName As String)
		Dim doc As Document = Application.DocumentManager.MdiActiveDocument
		Dim db As Database = doc.Database
		Using db
			'object obj = Application.GetSystemVariable("DWGTITLED");
			' Save the active drawing 
			If Not Directory.Exists(SavedDirectory) Then
				Directory.CreateDirectory(SavedDirectory)
			End If
			db.SaveAs(SavedDirectory + fileName, False, DwgVersion.Current, doc.Database.SecurityParameters)
		End Using
	End Sub

	''' <summary>
	''' Send a drawing file to a network stream
	''' </summary>
	''' <param name="fileName">file name to open and send to TCP</param>
	Private Sub Send(fileName As String)
		Dim fs = New FileStream(SavedDirectory + fileName, FileMode.Open, FileAccess.Read)
		Dim length As Integer = Convert.ToInt32(fs.Length)
		Dim reader = New BinaryReader(fs)
		Try
			Dim stream As NetworkStream = _tcpClient.GetStream()
			Dim writer = New BinaryWriter(stream)
			writer.Write(length)
			Dim buffer As Byte()
			Do
				' Read data from file
				buffer = reader.ReadBytes(PacketSize)
				' Write data to Network Stream
				writer.Write(buffer)
			Loop While buffer.Length = PacketSize
			writer.Flush()
			'writer.Close();	// do not close the TcpClient connection
			reader.Close()
				' Handle errors
		Catch ex As System.Exception
		End Try
		fs.Close()
	End Sub

	''' <summary>
	''' Receive the rendered photo file back
	''' </summary>
	''' <param name="fileName">photo file name</param>
	Private Sub ReceivePhoto(fileName As String)
		Dim filePath As String = SavedDirectory + fileName
		Dim readBuffer = New Byte(PacketSize) {}
		Dim receivedStream As NetworkStream = _tcpClient.GetStream()
		Dim reader = New BinaryReader(receivedStream)
		Dim streamLength As Integer = reader.ReadInt32()
		Using mStream = New MemoryStream()
			While streamLength > 0
				Dim lData As Integer = receivedStream.Read(readBuffer, 0, PacketSize)
				mStream.Write(readBuffer, 0, lData)
				streamLength -= lData
			End While
			If File.Exists(filePath) Then
				File.Delete(filePath)
			End If
			Dim fs As FileStream = File.OpenWrite(filePath)
			mStream.WriteTo(fs)
			fs.Close()
		End Using
	End Sub
	#End Region

	#Region "ServerPlugin"
	<CommandMethod("StartServer")> _
	Public Sub StartServer()
		Dim dwgFileName As String = "Rendering.dwg"
		Dim imageFileName As String = "Picture.png"
		_editor.WriteMessage(vbLf + "Starting ..." + vbLf)
		Receiver()
		Render(dwgFileName, imageFileName)
		Transmitter(dwgFileName)
		Disconnect()
		System.Threading.Thread.Sleep(2000)
	End Sub

	''' <summary>
	''' Receive connection and put file in queue
	''' </summary>
	Private Sub Receiver()
		Dim ipAddress__1 As IPAddress = IPAddress.Parse(IpServer)
		Dim tcpListener = New TcpListener(ipAddress__1, PortNum)
		tcpListener.Start()
		Try
			' Perform a blocking call to accept requests
			_tcpClient = tcpListener.AcceptTcpClient()
			' Keep waiting until a client is connected at http://127.0.0.1:8000
			If _tcpClient.Connected Then
				_client = New ClientWrapper()
				_client.TcpClient = _tcpClient

				Dim readBuffer = New Byte(PacketSize) {}
				Dim requestStream As NetworkStream = _tcpClient.GetStream()
				Dim reader = New BinaryReader(requestStream)
				Dim streamLength As Integer = reader.ReadInt32()
				' convert a network stream to a memory stream
				Dim responseStream = New MemoryStream()
				While streamLength > 0
					Dim lData As Integer = requestStream.Read(readBuffer, 0, PacketSize)
					responseStream.Write(readBuffer, 0, lData)
					streamLength -= lData
				End While
				_editor.WriteMessage(vbLf + "Received file ..." + vbLf)
				_client.File = responseStream
			End If
		Catch e As System.Exception
		End Try
		tcpListener.[Stop]()
	End Sub

	''' <summary>
	''' Render a DWG drawing to a PNG image
	''' </summary>
	''' <param name="dwgFileName">DWG file name to render</param>
	''' <param name="imageFileName">PNG file name of the output</param>
	Private Sub Render(dwgFileName As String, imageFileName As String)
		Dim filePath As String = SavedDirectory + dwgFileName
		Dim mStream As MemoryStream = _client.File
		If Not Directory.Exists(SavedDirectory) Then
			Directory.CreateDirectory(SavedDirectory)
		End If
		If File.Exists(filePath) Then
			File.Delete(filePath)
		End If
		Dim fs As FileStream = File.OpenWrite(filePath)
		mStream.WriteTo(fs)
		fs.Close()

		' Open a drawing in AutoCAD 2009
		Dim doc As Document = Application.DocumentManager.Open(filePath)

		' Open a drawing in AutoCAD 2013
		'Dim docCol As DocumentCollection = Application.DocumentManager
		'Dim doc As Document
		'doc = DocumentCollectionExtension.Open(docCol, filePath)

		filePath = SavedDirectory + imageFileName
		Dim vpn As Integer = System.Convert.ToInt32(Application.GetSystemVariable("CVPORT"))
		Dim gsv As GraphicsSystem.View = doc.GraphicsManager.GetGsView(vpn, True)
		Using view As GraphicsSystem.View = gsv.Clone(True, True)
			' Do not render the drawing if there are no rendering objects
			'if (view.BackgroundId == ObjectId.Null) return;

			Using dev As Device = doc.GraphicsManager.CreateAutoCADOffScreenDevice()
				'dev.OnSize(doc.GraphicsManager.DeviceIndependentDisplaySize)
				dev.DeviceRenderType = RendererType.FullRender
				dev.Add(view)
				Try
					Dim bitmap As Bitmap = view.RenderToImage()
					Using bitmap
						bitmap.Save(filePath)
						fs = File.OpenRead(filePath)
						_client.Result = fs
					End Using

				Catch ex As System.Exception
				End Try
			End Using
		End Using
	End Sub

	''' <summary>
	''' Send back the result
	''' </summary>
	''' <param name="fileName"></param>
	Private Sub Transmitter(fileName As String)
		Dim fs = New FileStream(SavedDirectory + fileName, FileMode.Open, FileAccess.Read)
		Dim length As Integer = Convert.ToInt32(fs.Length)
		Dim reader = New BinaryReader(fs)
		Dim buffer As Byte()
		' Data buffer
		Dim writer = New BinaryWriter(_client.TcpClient.GetStream())
		writer.Write(length)
		Do
			'read data from file
			buffer = reader.ReadBytes(PacketSize)
			'write data to Network Stream
			writer.Write(buffer)
		Loop While buffer.Length = PacketSize
		writer.Flush()
		writer.Close()
		reader.Close()
		fs.Close()
	End Sub

	'stops server
	<CommandMethod("StopServer")> _
	Public Sub StopServer()

	End Sub
	#End Region
End Class

 

-Khoa

Contributor
dj-nemo
Posts: 16
Registered: ‎08-17-2012
Message 12 of 26 (341 Views)

Re: plugin problem in vb .net

08-24-2012 07:01 AM in reply to: khoa.ho

Hi Khoa

 

Let's say i am an arhitect. i made drawing of some building and i want some photos of my new building. I set up everything to render, but instead to push the button render i use my "SENDTORENDER" command. Rendering can be sometimes operation that takes a really long time. So when i will use command i will send this current drawing to some more powerful PC and so it will take less time to render file. After rendering on powerful PC ends it' will send image back to my PC.

 

So in short we have one powerfull PC in office that will render files and all the employees will send to this computer work. Since we can't make it multithreading i can't have one thread taking clients all the time. So server will work in while(true) loop and thaking clients. If it will be busy nobody can't connect.

 

Sorry for confusion other thay with sending back dwg file i just want to test if tcp conversation works both ways fine.

 

Thank for so much help 

 

 

Mentor
khoa.ho
Posts: 224
Registered: ‎09-15-2011
Message 13 of 26 (334 Views)

Re: plugin problem in vb .net

08-24-2012 09:37 AM in reply to: dj-nemo

You are welcome. This is a very interesting topic to deal with multi-threading and parallel programming in AutoCAD. Gopinath Target from Autodesk had a lesson about it on AU, but it was dealing with how to invoke the main AutoCAD UI thread in the background process. He also uses a BackgroundWorker to perform asynchronous operations in a background thread. Let me time to play with his solution.

 

The idea to use TCP as an asynchronous communication between server and clients is very similar to the popular Node.js (Server-side JavaScript based on Google's V8 engine). This Google engine is also internally single-threaded like AutoCAD or RealDWG. The TCP solution will become the cloud computing one as seen on the ADN DevBlog ( http://adndevblog.typepad.com/cloud_and_mobile/ ). Autodesk already has Autodesk 360 Rendering ( http://rendering.360.autodesk.com/ ) service to remotely render images on the cloud. However, we want to learn the technology secrets behind. It's tough to catch all those new good things as we have to spend time on company projects every day.

 

To keep it simple with your project, I will go back to use TCP concept for non-blocking requests to render images on the server.

 

-Khoa

Mentor
khoa.ho
Posts: 224
Registered: ‎09-15-2011
Message 14 of 26 (305 Views)

Re: plugin problem in vb .net

08-26-2012 01:38 PM in reply to: khoa.ho

Hi dj-nemo,

The problem of view.RenderToImage() is the missing of HostApplicationServices.WorkingDatabase = doc.Database. Now it works to produce a PNG image.

We use TcpClient to connect, send, and receive stream data over a network in synchronous blocking mode. Each server and client has its own TcpClient to request and response network stream back to the central TCP/IP. This HTTP address is the gateway for communication between server and client.

The order of communication between server and client shows as below:

1. Server.ListenAndReceive
2. Client.SendStreamToServer
3. Server.Render
4. Server.ResponeStreamToClient
5. Client.ReceiveStreamFromServer

Open two AutoCAD, one works as a server with command StartRenderServer first, and another works as a client with command SendToRender. After running the server AutoCAD, on the client AutoCAD, draw some 3D objects, then hit command SendToServer. The client will save a new rendered image (Picture.png) to folder C:\ClientServer.

I rewrote the new code with better reusable methods. But you still have to test and add more features in your project. This code is just basic without multiple connected clients and something more, and has some possible potential bugs. I keep it simple and fundamental to easily understand.

 

#Region "Client-Server"
''' <summary>
''' Wrapper for clients in queue
''' </summary>
Public Structure ClientWrapper
	Public Property File() As MemoryStream
		Get
			Return m_File
		End Get
		Set
			m_File = Value
		End Set
	End Property
	Private m_File As MemoryStream
	Public Property Result() As FileStream
		Get
			Return m_Result
		End Get
		Set
			m_Result = Value
		End Set
	End Property
	Private m_Result As FileStream
End Structure

''' <summary>
''' Server-Client plugin
''' </summary>
Public Class ServerClientPlugin
	Private Const IpServer As String = "127.0.0.1"
	Private Const PortNum As Integer = 8000
	Private Const PacketSize As Integer = 4096
	Private Const ServerFolder As String = "C:\ServerFolder\"
	' A shared folder in a network drive
	Private Const ClientFolder As String = "C:\ClientFolder\"
	' A local folder at client machine
	Private _client As ClientWrapper
	Private ReadOnly _editor As Editor = Application.DocumentManager.MdiActiveDocument.Editor
	Private _tcpClient As System.Net.Sockets.TcpClient

	#Region "ServerPlugin"
	<CommandMethod("StartRenderServer")> _
	Public Sub StartRenderServer()
		Dim dwgFileName As String = "ServerDrawing.dwg"
		Dim imageFileName As String = "Picture.png"
		_editor.WriteMessage(vbLf + "Starting ..." + vbLf)
		ListenAndReceive()
		Render(dwgFileName, imageFileName)
		ResponseStreamToClient(imageFileName)
		DisconnectTCP()
		'System.Threading.Thread.Sleep(2000);
	End Sub

	''' <summary>
	''' Receive connection and put file in queue
	''' </summary>
	Private Sub ListenAndReceive()
		Dim ipAddress__1 As IPAddress = IPAddress.Parse(IpServer)
		Dim tcpListener = New TcpListener(ipAddress__1, PortNum)
		tcpListener.Start()
		Try
			' Perform a blocking call to accept requests
			_tcpClient = tcpListener.AcceptTcpClient()
			' Keep waiting until a client is connected at http://127.0.0.1:8000
			If _tcpClient.Connected Then
					'TcpClient = _tcpClient,
				_client = New ClientWrapper() With { _
					.File = ReadStreamFromTCP() _
				}
				_editor.WriteMessage(vbLf + "Received file ..." + vbLf)
			End If
		Catch ex As System.Exception
			_editor.WriteMessage(ex.Message + vbLf + ex.StackTrace)
		End Try
		tcpListener.[Stop]()
	End Sub

	''' <summary>
	''' Render a DWG drawing to a PNG image
	''' </summary>
	''' <param name="dwgFileName">DWG file name to render</param>
	''' <param name="imageFileName">PNG file name of the output</param>
	Private Sub Render(dwgFileName As String, imageFileName As String)
		Try
			Dim filePath As String = ServerFolder + dwgFileName
			Dim responseStream As MemoryStream = _client.File
			If Not Directory.Exists(ServerFolder) Then
				Directory.CreateDirectory(ServerFolder)
			End If
			If File.Exists(filePath) Then
				File.Delete(filePath)
			End If
			Dim fileStream As FileStream = File.OpenWrite(filePath)
			responseStream.WriteTo(fileStream)
			fileStream.Close()

			' Open the new saved drawing in AutoCAD 2009
			Dim doc As Document = Application.DocumentManager.Open(filePath)

			' Open the new saved drawing in AutoCAD 2013
			'Dim docCol As DocumentCollection = Application.DocumentManager
			'Dim doc As Document
			'doc = DocumentCollectionExtension.Open(docCol, filePath)

			Using doc
				Dim workDb As Database = HostApplicationServices.WorkingDatabase
				HostApplicationServices.WorkingDatabase = doc.Database

				filePath = ServerFolder + imageFileName
				Dim vpn As Integer = System.Convert.ToInt32(Application.GetSystemVariable("CVPORT"))
				Dim gsv As GraphicsSystem.View = doc.GraphicsManager.GetGsView(vpn, True)
				Using view As GraphicsSystem.View = gsv.Clone(True, True)
					Using dev As Device = doc.GraphicsManager.CreateAutoCADOffScreenDevice()
						'dev.OnSize(doc.GraphicsManager.DeviceIndependentDisplaySize)
						dev.DeviceRenderType = RendererType.FullRender
						dev.Add(view)
						Dim bitmap As Bitmap = view.RenderToImage()
						Using bitmap
							bitmap.Save(filePath)
							fileStream = File.OpenRead(filePath)
							_client.Result = fileStream
						End Using
					End Using
				End Using
				' Restore the previous working database back
				HostApplicationServices.WorkingDatabase = workDb
			End Using
		Catch ex As System.Exception
			_editor.WriteMessage(ex.Message + vbLf + ex.StackTrace)
		End Try
	End Sub

	''' <summary>
	''' Send back the result
	''' </summary>
	''' <param name="fileName"></param>
	Private Sub ResponseStreamToClient(fileName As String)
		Try
			Dim fileStream = New FileStream(ServerFolder + fileName, FileMode.Open, FileAccess.Read)
			WriteStreamToTCP(fileStream)
			fileStream.Close()
		Catch ex As System.Exception
			_editor.WriteMessage(ex.Message + vbLf + ex.StackTrace)
		End Try
	End Sub

	'stops server
	<CommandMethod("StopRenderServer")> _
	Public Sub StopRenderServer()

	End Sub
	#End Region

	#Region "ClientPlugin"
	<CommandMethod("SendToRender")> _
	Public Sub SendToRender()
		Dim inputFileName As String = "ClientDrawing.dwg"
		Dim outputFileName As String = "Picture.png"
		ConnectTCP()
		SaveCurrentDrawingToFile(inputFileName)
		SendStreamToServer(inputFileName)
		ReceiveStreamFromServer(outputFileName)
		DisconnectTCP()
	End Sub

	Private Sub ConnectTCP()
		Try
			_tcpClient = New System.Net.Sockets.TcpClient()
			_tcpClient.Connect(IpServer, PortNum)
		Catch ex As System.Exception
			_editor.WriteMessage(ex.Message + vbLf + ex.StackTrace)
		End Try
	End Sub

	Private Sub DisconnectTCP()
		' Shutdown and end connection
		_tcpClient.Close()
	End Sub

	''' <summary>
	''' Save the current drawing to a file
	''' </summary>
	''' <param name="fileName">file name to save</param>
	Private Sub SaveCurrentDrawingToFile(fileName As String)
		Dim doc As Document = Application.DocumentManager.MdiActiveDocument
		Dim db As Database = doc.Database
		Using db
			'object obj = Application.GetSystemVariable("DWGTITLED");
			' Save the active drawing 
			If Not Directory.Exists(ClientFolder) Then
				Directory.CreateDirectory(ClientFolder)
			End If
			db.SaveAs(ClientFolder + fileName, False, DwgVersion.Current, doc.Database.SecurityParameters)
		End Using
	End Sub

	''' <summary>
	''' Send a drawing file to a network stream
	''' </summary>
	''' <param name="fileName">file name to open and send to TCP</param>
	Private Sub SendStreamToServer(fileName As String)
		Try
			Dim fileStream = New FileStream(ClientFolder + fileName, FileMode.Open, FileAccess.Read)
			WriteStreamToTCP(fileStream)
			fileStream.Close()
		Catch ex As System.Exception
			_editor.WriteMessage(ex.Message + vbLf + ex.StackTrace)
		End Try
	End Sub

	''' <summary>
	''' Receive the rendered photo file back
	''' </summary>
	''' <param name="fileName">photo file name</param>
	Private Sub ReceiveStreamFromServer(fileName As String)
		Try
			Dim responseStream = ReadStreamFromTCP()

			Dim filePath As String = ClientFolder + fileName
			If File.Exists(filePath) Then
				File.Delete(filePath)
			End If
			Dim fileStream As FileStream = File.OpenWrite(filePath)
			' Save memory stream to physical file
			responseStream.WriteTo(fileStream)
			fileStream.Close()
		Catch ex As System.Exception
			_editor.WriteMessage(ex.Message + vbLf + ex.StackTrace)
		End Try
	End Sub
	#End Region

	#Region "Shared methods"
	Private Function ReadStreamFromTCP() As MemoryStream
		Dim readBuffer = New Byte(PacketSize) {}
		' Get a network stream from TCP/IP address
		Dim requestStream As NetworkStream = _tcpClient.GetStream()
		' Read binary stream from TCP/IP address
		Dim reader = New BinaryReader(requestStream)
		Dim streamLength As Integer = reader.ReadInt32()
		' Convert a network stream to a memory stream
		Dim responseStream = New MemoryStream()
		While streamLength > 0
			Dim lData As Integer = requestStream.Read(readBuffer, 0, PacketSize)
			responseStream.Write(readBuffer, 0, lData)
			streamLength -= lData
		End While
		Return responseStream
	End Function

	Private Sub WriteStreamToTCP(stream As Stream)
		Dim reader = New BinaryReader(stream)
		' Get a network stream from TCP/IP address
		Dim requestStream As NetworkStream = _tcpClient.GetStream()
		' Write binary stream to TCP/IP address
		Dim writer = New BinaryWriter(requestStream)
		Dim length As Integer = Convert.ToInt32(stream.Length)
		writer.Write(length)
		Dim buffer As Byte()
		Do
			' Read data from file
			buffer = reader.ReadBytes(PacketSize)
			' Write data to Network Stream
			writer.Write(buffer)
		Loop While buffer.Length = PacketSize
		writer.Flush()
		'writer.Close();	// do not close the TcpClient connection
		reader.Close()
	End Sub
	#End Region
End Class

 

-Khoa

Contributor
dj-nemo
Posts: 16
Registered: ‎08-17-2012
Message 15 of 26 (283 Views)

Re: plugin problem in vb .net

08-27-2012 08:46 AM in reply to: khoa.ho

I found one more problem in line with type Bitmap

 

Dim bitmap As Bitmap = view.RenderToImage()

 

The problem is i can't import System.Drawing

 

It's says 

 Namespace or type specified in the Imports 'System.Drawing' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases.

 

Should i use something instead or can i inport somehow dll that i had downloaded from internet?

 

 

 

Mentor
khoa.ho
Posts: 224
Registered: ‎09-15-2011
Message 16 of 26 (269 Views)

Re: plugin problem in vb .net

08-28-2012 01:27 PM in reply to: dj-nemo

Hi dj-nemo,

 

I hope you may solve this .NET reference issue. System.Drawing namespace is seen from all .NET frameworks since 1.1, 2.0, 3.0, 3.5, 4.0 and 4.5. See the MSDN link: http://msdn.microsoft.com/en-us/library/xs6ftd89(v=vs.100)

 

Please check the "Add Reference" dialog in Visual Studio to import the correct System.Drawing version in your project. It will also work if it has lower .NET version with your current AutoCAD plug-in.

 

-Khoa

Contributor
dj-nemo
Posts: 16
Registered: ‎08-17-2012
Message 17 of 26 (263 Views)

Re: plugin problem in vb .net

08-28-2012 03:00 PM in reply to: khoa.ho

Hi

 

after adding System.drawing via add reference it is ok.

 

Now i have picture rendered from the top in 2D mode. How can i put view in same position cient has.

 

I am attaching example of my simple dwg file, wanted bitmap and bitmap i get

 

Contributor
dj-nemo
Posts: 16
Registered: ‎08-17-2012
Message 18 of 26 (250 Views)

Re: plugin problem in vb .net

08-29-2012 11:16 AM in reply to: dj-nemo

Hi

i found another question. I was wondering if there is any document from autodesk to tell me how it's rendering made. As i saw autocad can use moltiple cores. How is this made. Is it using data paralelism or process paralelism and so on. Which rendering technics are used.

If you ever saw some data about that pleaselet me know

 

Domen

Contributor
dj-nemo
Posts: 16
Registered: ‎08-17-2012
Message 19 of 26 (227 Views)

Re: plugin problem in vb .net

09-06-2012 05:33 AM in reply to: dj-nemo

Dear Khoa i hope you are still there. 

 

can you in few words explain me what this code is doing.

                Using doc
                    Dim workDb As Database = HostApplicationServices.WorkingDatabase
                    HostApplicationServices.WorkingDatabase = doc.Database
                    filePath = ServerFolder + imageFileName
                    Dim vpn As Integer = System.Convert.ToInt32(Application.GetSystemVariable("CVPORT"))
                    Dim gsv As GraphicsSystem.View = doc.GraphicsManager.GetGsView(vpn, True)
                    Using view As GraphicsSystem.View = doc.GraphicsManager.v
                        Using dev As Device = doc.GraphicsManager.CreateAutoCADOffScreenDevice()
                            dev.DeviceRenderType = RendererType.FullRender
                            dev.Add(view)
                            Dim bitmap As Bitmap = view.RenderToImage()
                            Using bitmap
                                bitmap.Save(filePath)
                                fileStream = File.OpenRead(filePath)
                                _client.Result = fileStream
                            End Using
                        End Using
                    End Using

                    ' Restore the previous working database back
                    HostApplicationServices.WorkingDatabase = workDb
                End Using

 

What is CVPORT system variable for? in my case it's 2 (i think this mean we have 3D scene am i right?)

After that we are prepering view for render, am i right?

 

 

 

 

Mentor
khoa.ho
Posts: 224
Registered: ‎09-15-2011
Message 20 of 26 (223 Views)

Re: plugin problem in vb .net

09-06-2012 07:09 AM in reply to: dj-nemo

Hi dj-nemo,

 

I will have a look again on your code around the end of my working day (US Central Time). Last week I was very busy and did not have time to track this .NET forum. I will be back to see this issue.

 

-Khoa

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.