Announcements
Due to scheduled maintenance, the Autodesk Community will be inaccessible from 10:00PM PDT on Oct 16th for approximately 1 hour. We appreciate your patience during this time.
.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to use dwgviewrAcCtrl.dll in the client machine without installing DWG trueview on that machine ?

10 REPLIES 10
SOLVED
Reply
Message 1 of 11
trithuongle
937 Views, 10 Replies

How to use dwgviewrAcCtrl.dll in the client machine without installing DWG trueview on that machine ?

Good morning everybody, i have a question.

I have a project that need to embed DWG viewer control(dwgviewrAcCtrl.dll) into winforms.

I'm using Autocad mechanical 2020 , Visual studio 2019 , DWG trueview 2021 .

The project run well on my machine, but cannot run on the client machine which don't have DWG true view installed.

Is there anyway to run this project without  installing DWG trueview on client machine ?

Thanks in advance!

10 REPLIES 10
Message 2 of 11
norman.yuan
in reply to: trithuongle

Dwg TrueView is a feature-strip-down light version of AutoCAD. AcCtrl.dll wraps some basic AutoCAD's drawing viewing features and expose them as COM component. This DLL can only be installed and used in a computer either AutoCAD or Dwg TrueView is installed (that is, it is dependent on other required AutoCAD components in order to work). 

 

So, no, you app that uses AcCtrl.dll requires the computer to have AutoCAD, or TrueView installed (then, you may want to ask yourself: what is the point to run your app to view drawing with a computer that has AutoCAD/TrueView installed?).

 

Norman Yuan

Drive CAD With Code

EESignature

Message 3 of 11
trithuongle
in reply to: norman.yuan

@norman.yuan   Good morning. Thanks for your reply.

The client computer has Autocad mechanical 2020 installed but no DWG true view.

My purpose is that i want to embed the drawing (.dwg) in to winforms for user to view it / rotate / zoom without opening it , then i selected DWG true view's control (dwgviewrAcCtrl.dll ) to do this. 

So is there any way for the client computer with Autocad ONLY can use the developed tool with DWG true view control ?  

Thanks in advance!

Message 4 of 11
trithuongle
in reply to: trithuongle

@norman.yuan  On the otherway, i tried another solution with "thumbnail" by the below code

private void GetOuterDWGModelBitmap(string fileName)
{
    //object temp = AcAp.GetSystemVariable("THUMBSAVE");
    string thumbVarName = "THUMBSIZE";
    int oldThumbSize = System.Convert.ToInt32(AcAp.GetSystemVariable(thumbVarName));
    int newThumbSize = 8;
    int imgW = thumbnailPic.Width;
    int imgH = thumbnailPic.Height;
    
    try
    {
	AcAp.SetSystemVariable(thumbVarName, newThumbSize);

	using (Database OuterDB = new Database())
	{
	    OuterDB.ReadDwgFile(fileName, System.IO.FileShare.Read, false, "");
    	    using (Transaction tr = OuterDB.TransactionManager.StartTransaction())
    	    {
		BlockTable bt = (BlockTable)tr.GetObject(OuterDB.BlockTableId, OpenMode.ForRead);
		BlockTableRecord blk = (BlockTableRecord)tr.GetObject(bt["*Model_Space"], OpenMode.ForRead);

		ImageSource imgsrc=Autodesk.AutoCAD.Windows.Data.CMLContentSearchPreviews.GetBlockTRThumbnail(blk);
		srcImage = ImageSourceToGDI(imgsrc as System.Windows.Media.Imaging.BitmapSource);
		if (srcImage == null)
		{
    			tr.Abort();
    			return;
		}
		thumbnailPic.Image = ResizeImage(srcImage, new Size(imgW, imgH));

		tr.Commit();
    	     }
    	}
    }
    catch (Exception ex)
    {
	if (ex.Message == "eFileSharingViolation")
	{
    		MessageBox.Show("File is currently opened by Autocad. Please check again!", this.Text,
       						MessageBoxButtons.OK,
       						MessageBoxIcon.Warning);
	}
    }
    finally
    {
	AcAp.SetSystemVariable(thumbVarName, oldThumbSize);
    }
}

private System.Drawing.Image ImageSourceToGDI(System.Windows.Media.Imaging.BitmapSource src)
{
    Image retImage = null;
    MemoryStream ms = null;
    try
    {
	ms = new MemoryStream();
	var encoder = new System.Windows.Media.Imaging.BmpBitmapEncoder();
	encoder.Frames.Add(System.Windows.Media.Imaging.BitmapFrame.Create(src));
	encoder.Save(ms);
	ms.Flush();
	retImage = System.Drawing.Image.FromStream(ms);
    }
    catch (Exception ex)
    {
	MessageBox.Show("Error : " + ex.Message, this.Text,
	MessageBoxButtons.OK,
	MessageBoxIcon.Error);
    }
    finally
    {
	ms.Dispose();
    }

    return retImage;
}

The problem is the quality of thumnail picture when add it to picture box is very not good although i tried to 

set the "THUMBSIZE" systemvariable to 8. 

 

trithuongle_0-1691210102148.png

Is there any way to improve thumbnail's image quality when embed it to picture box ?

Thanks in advance!

Message 5 of 11
norman.yuan
in reply to: trithuongle

When AutoCAD is installed, there is AcCtrl.dll is available, as dwgvieweAcCtrl.dll is with TrueView installation. They both are the COM control of the strip-down version of AutoCAD with dwgviewrAcCtrl.ll exposes a bit of more AutoCAD's viewing features.

 

Since your target users/computers are all have AutoCAD installed, thus Acctrl.dll should be available. SO you can use AcCtrl.dll, instead of dwgviewrAcCtrl.dll. As I said, I am not sure the differences of available drawing viewing features between the two, but it would be the same in terms of the visual effect of showing drawings as showing in AutoCAD. I guess you are using 64-bit AutoCAD, so, before adding AcCtrl.dll control to your Win Form, make sure your VS project targets x64 platform, not Any CPU/x86.

 

Again, depending how the purpose of showing drawing that is not currently loaded into AutoCAD, using either dwgviewrAcCtrl.dll or AcCtrl.dll could be a bit of too much over headed. One of my articles might give you another option:

 

https://drive-cad-with-code.blogspot.com/2022/10/extract-entity-image-from-side-loaded.html 

 

The quality of the image generated as the article described is quite well when done one entity at a time. But I would think it would also to relatively good when done with a few more entities together; but with a crowded group of entities, you have try to see.

 

Just to be warned, since the code in the article uses Autodesk.AutoCAD.Internal namespace, you would take the risk of the code being broken without official warning (but it has been there for quite long).

 

 

 

Norman Yuan

Drive CAD With Code

EESignature

Message 6 of 11
trithuongle
in reply to: norman.yuan

@norman.yuan  Thank for your reply. So the second solution that you provided worked !

The graphic is better now like below.

trithuongle_1-1691291408794.png

On the other side, the first solution that use AcCtrl.dll at "C:\Program Files\Common Files\Autodesk Shared" 

will force my Visual studio 2019(32bits) shutdown. I'm finding the way to solve this also.

 

Once again, thank you alot for your solution.

Message 7 of 11
norman.yuan
in reply to: trithuongle

There is no reason not using VS2022, which has 64-bit version. Also as I said, to use AcCtrl.dll from 64-bit AutoCAD with .NET framework, the project has to set to target x64 platform.

 

Norman Yuan

Drive CAD With Code

EESignature

Message 8 of 11
trithuongle
in reply to: norman.yuan

@norman.yuan @Thanks for your reply. I just quicktested with vba in autocad by reference to acctrl.dll ,it worked perfectly . So i wonder if the VS 2022 is compatible with objectarx 2020 sdk ? Cause i knew that the sdk is compatible with VS2019 or VS2017

Thanks again! 

Message 9 of 11
trithuongle
in reply to: norman.yuan

@norman.yuan  Good evening!

Finally i can insert the AcCtrl into winform.

But there 's still a problem that when i tried to change the drawing source.

It seem that the child autocad that AcCtrl hold will get crash (the main autocad app is still alive) like below:

trithuongle_0-1691417142557.png

        //Help method to load dwg to AcCtrl:
        private void LoadDwgFile(string fileName)
        {
            try
            {
                if (this.axAcCtrl.Src != null)
                {
                    this.axAcCtrl.src=null;
                }

                if (System.IO.File.Exists(fileName))
                {
                    this.axAcCtrl.src=fileName;
                }
                else
                {
                    MessageBox.Show("Drawing file is not exist!", formOwner ,
                                      MessageBoxButtons.OK,
                                      MessageBoxIcon.Warning);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error : " + ex.Message, formOwner ,
                                       MessageBoxButtons.OK,
                                       MessageBoxIcon.Error);
            }
        }

So is there anyway for AcCtrl to change the source without generating the crash window above ?

Thanks in advance!

Message 10 of 11
norman.yuan
in reply to: trithuongle

Assume you have 64-bit AutoCAD installed (who has not, this days?), and also use 64-bit VS2022, did you do as I noted in previous post: set the VS project to target x64 platform, NOT x86, or Any CPU!

 

I just did:

1. created a simple Win Form EXE with a single form;

2. add AcCtrl by rigt-clicking "Choose Item..." in the Tool Box window;

3. Drag the AcCtrl control onto the Form

4. Add one-line of code:

        private void Form1_Load(object sender, EventArgs e)
        {
            axAcCtrl1.src=@"C:\Temp\Test.dwg";
        }

 5. Hit F5 to run.

Here was what I got:

normanyuan_0-1691417311969.png

At this time, if you go to "Task Manager" to see the process detail, you would see, besides the EXE running, there is also an "AutoCAD Application" process runs as background process. As you can see, this would effectively eats up a lot of computer resources just for the purpose of showing the "picture of drawing" in better visual quality. The bad thing with using AcCtrl is the lack of necessary API being exposed. For example, if you use it in an EXE, when the EXE end, the Acad application in the background could/would remain running, which could cause issues.

 

I would avoid to use AcCtrl just for viewing drawing as picture with better visual quality whenever possible, and fortunately, I have never needed to, so far.

Norman Yuan

Drive CAD With Code

EESignature

Message 11 of 11
trithuongle
in reply to: norman.yuan

@norman.yuan Thank for your reply, I also tested alot with both solution that you provided, i have to admit that 

the AcCtrl is really lack of document/ information about using this control. I also found the old post from Kean Walmsley https://www.keanw.com/2008/03/embedding-autoc.html?fbclid=IwAR3F3saDhoIGWM6jDI797ZzQQUt6Gp4kZLOhVgu-...

or the help in Autocad2024

https://help.autodesk.com/view/OARX/2024/ENU/?guid=GUID-D2D6F91A-DC86-43F3-8637-AAF6AF2254F6

I folowed these and made a form with AcCtrl embeded. At the first time the control suceeded to load the drawing.

But problem is when i change the axAcCtrl.src=[ another drawing link] => the control will generate the message box like below 

trithuongle_0-1691503947498.png

Then if i close the error message, the form become freeze(unable to move or do anything).

By the way, at the beginning my purpose is to let the client can see the drawing's content without opening it by normal way, then they can pan/ zoom or even change the view to Isometric. So i thought about using AcCtrl.dll or DwgTrueView...vv

But i think the AcCtrl.dll's control is really lack of documents or help. For temporary solution,now i'm continuing with "Utils.GetBlockImage". but  i really appreciate that if there is any way to fix above problem with AcCtrl.dll 

Thanks in advance!

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

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report