Author Topic: Use WPF dialog button to draw a line  (Read 8486 times)

0 Members and 1 Guest are viewing this topic.

Coder

  • Swamp Rat
  • Posts: 827
Use WPF dialog button to draw a line
« on: May 18, 2015, 07:24:24 AM »
Hello guys .

I am just learning how to use the WPF in AutoCAD and hope someone could help me to learn how to do this process to allow me to do future programs on my own later on.

This is the simple dialog with one button entitled "Draw Line"

I need to press the button then the program should draw the line from 0,0,0 to 10,10,0

What is the format that I should build the program with to be able to run it in Autocad ?

Many thanks in advance

Code - C#: [Select]
  1. <Window x:Class="WpfApplication1.MainWindow"
  2.         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3.         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4.         Title="MainWindow" Height="100" Width="250" HorizontalAlignment="Left" VerticalAlignment="Top">
  5.     <Grid Margin="0,0,-8,-3">
  6.         <Button x:Name="Draw" Content="Draw Line" HorizontalAlignment="Left" Margin="65,18,0,0" VerticalAlignment="Top" Width="100" Height="30" Click="Draw_Click"/>
  7.     </Grid>
  8.  

And this is the C# codes that I use to draw a line via dll files .

Code - C#: [Select]
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using System.Text;
  6. using Autodesk.AutoCAD.Runtime;
  7. using Autodesk.AutoCAD.ApplicationServices;
  8. using Autodesk.AutoCAD.DatabaseServices;
  9. using Autodesk.AutoCAD.Geometry;
  10. using App = Autodesk.AutoCAD.ApplicationServices.Application;
  11.  
  12. namespace WindowsFormsApplication1
  13. {
  14.     class DrawLine
  15.     {
  16.         [CommandMethod("Drline")]
  17.         static public void line()
  18.         {
  19.             Document acDoc = App.DocumentManager.MdiActiveDocument;
  20.             Database acCurDb = acDoc.Database;
  21.             using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
  22.             {
  23.                 BlockTable acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable;
  24.                 BlockTableRecord acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
  25.                 Line acLine = new Line(new Point3d(0, 0, 0), new Point3d(10, 10, 0));
  26.                 acBlkTblRec.AppendEntity(acLine);
  27.                 acTrans.AddNewlyCreatedDBObject(acLine, true);
  28.                 acTrans.Commit();
  29.             }
  30.         }
  31.     }
  32. }
  33.  

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: Use WPF dialog button to draw a line
« Reply #1 on: May 18, 2015, 07:35:43 AM »
What is the format that I should build the program with to be able to run it in Autocad ?
Managed DLL, like your usual managed .net extension.

Coder

  • Swamp Rat
  • Posts: 827
Re: Use WPF dialog button to draw a line
« Reply #2 on: May 18, 2015, 08:29:17 AM »
What is the format that I should build the program with to be able to run it in Autocad ?
Managed DLL, like your usual managed .net extension.

Hi ,

When I built the dll from the menu BUILD -> Build Solution I moved to autocad to run the program , I have found many dll files and they are the assemblies that included in the program  :-o

Which one that represents the program ? although the name of the program is WpfApplication1

BlackBox

  • King Gator
  • Posts: 3770
Re: Use WPF dialog button to draw a line
« Reply #3 on: May 18, 2015, 08:46:35 AM »
Assembly References, except for with rare exception, should have Copy Local == False.
"How we think determines what we do, and what we do determines what we get."

Coder

  • Swamp Rat
  • Posts: 827
Re: Use WPF dialog button to draw a line
« Reply #4 on: May 18, 2015, 08:54:13 AM »
Assembly References, except for with rare exception, should have Copy Local == False.
Thank you BlackBox

I turned all references to False and did not have any dll in the debug folder  :-(

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: Use WPF dialog button to draw a line
« Reply #5 on: May 18, 2015, 08:59:21 AM »
Coder... Be not lazy...  :-( RTFM. The answers of your questions can be looked for at the first pages of manuals often. Reading documentation is a need of each programmer. Don't expect that someone will do it for you (friendly advice).
« Last Edit: May 18, 2015, 09:06:47 AM by Andrey Bushman »

Coder

  • Swamp Rat
  • Posts: 827
Re: Use WPF dialog button to draw a line
« Reply #6 on: May 18, 2015, 09:15:47 AM »
Coder... Be not lazy...  :-( RTFM. The answers of your questions can be looked for at the first pages of manuals often. Reading documentation is a need of each programmer. Don't expect that someone will do it for you (friendly advice).

I am not Lazy Andrey , I am just asking for specific thing that I can't find elsewhere and the Help document for the .net is difficult to deal with and that is what I am facing at the current time .

This is the first time I am working with dialog in C# and we should expect mistakes like this  , right ?

Can you please tell me where can I find the answer for my first question in the Help document ?

Thank
« Last Edit: May 18, 2015, 09:27:50 AM by Coder »

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: Use WPF dialog button to draw a line
« Reply #7 on: May 18, 2015, 09:28:14 AM »
Quote
I turned all references to False and did not have any dll in the debug folder  :-(
You don't need all DLL files which you pointed in your screen. From my previous link:
Quote
The main DLL files of the AutoCAD .NET API that you will frequently use are:
  • AcCoreMgd.dll. Use when working within the editor, publishing and plotting, and defining commands and functions that can be called from AutoLISP.
  • AcDbMgd.dll. Use when working with objects stored in a drawing file.
  • AcMgd.dll. Use when working with the application and user interface.
  • AcCui.dll. Use when working with customization files.
...
Once a AutoCAD .NET API DLL is referenced, you must set the Copy Local property of the referenced DLL to False.
It [Copy Local] means for DLL of Object SDK only, instead of all DLL files of your project. Also your screen has nothing of your output DLL (it has DLL of SDK only).

Check the "Your project properties -> Application tab -> Output type". It must to be "Class Library".
« Last Edit: May 18, 2015, 09:38:04 AM by Andrey Bushman »

Coder

  • Swamp Rat
  • Posts: 827
Re: Use WPF dialog button to draw a line
« Reply #8 on: May 18, 2015, 09:37:56 AM »
You don't need all DLL files which you pointed in your screen. From my previous link:

They came out to debug folder automatically after I build the program and I am not the one who copied them .


Coder

  • Swamp Rat
  • Posts: 827
Re: Use WPF dialog button to draw a line
« Reply #9 on: May 18, 2015, 09:42:11 AM »
Check the "Your project properties -> Application tab -> Output type". It must to be "Class Library".

After changing it to class library and build the program , it throws errors .
Why should I change it to Class library and I am working with windows dialogs ?.

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: Use WPF dialog button to draw a line
« Reply #10 on: May 18, 2015, 09:47:03 AM »
They came out to debug folder automatically after I build the program and I am not the one who copied them .
Only cats are born automatically themselves. :) That files "appeared" because their "Copy Local" properties was True by default. You can delete them from your output directory manually, if they doesn't disappear when you launch rebuilding.

Quote from: Coder
Why should I change it to Class library and I am working with windows dialogs ?.
Because you write a .net extension for AutoCAD instead of autonomic application.
Quote from: Coder
After changing it to class library and build the program , it throws errors .
What is "it"? IDE or AutoCAD (compilation or runtime error)? Are you waiting, we will guess the text of your errors? :) Where is the text of your error messages?

Also, don't forget the .NET Framework version of your project must be the same which can be used by your AutoCAD version.
« Last Edit: May 18, 2015, 10:11:51 AM by Andrey Bushman »

BlackBox

  • King Gator
  • Posts: 3770
Re: Use WPF dialog button to draw a line
« Reply #11 on: May 18, 2015, 11:09:46 AM »
Perhaps you should consider using the AutoCAD .NET Wizard, until you're more familiar with configuring your own Solutions, Projects, etc., as it (the Wizard) will do much of the basics for you.


Cheers
"How we think determines what we do, and what we do determines what we get."

ChrisCarlson

  • Guest
Re: Use WPF dialog button to draw a line
« Reply #12 on: May 18, 2015, 12:09:19 PM »
Perhaps you should consider using the AutoCAD .NET Wizard, until you're more familiar with configuring your own Solutions, Projects, etc., as it (the Wizard) will do much of the basics for you.


Cheers

What he said! Just note that I don't think it has been updated for post VS 2012 yet.

BlackBox

  • King Gator
  • Posts: 3770
Re: Use WPF dialog button to draw a line
« Reply #13 on: May 18, 2015, 12:18:30 PM »
Perhaps you should consider using the AutoCAD .NET Wizard, until you're more familiar with configuring your own Solutions, Projects, etc., as it (the Wizard) will do much of the basics for you.


Cheers

What he said! Just note that I don't think it has been updated for post VS 2012 yet.

*Tips hat*

FWIW - I use it (the Wizard, albeit a customized version of) + Visual Studio 2013 to develop for 2012-2016 products.
"How we think determines what we do, and what we do determines what we get."

Coder

  • Swamp Rat
  • Posts: 827
Re: Use WPF dialog button to draw a line
« Reply #14 on: May 18, 2015, 01:40:28 PM »
Perhaps you should consider using the AutoCAD .NET Wizard, until you're more familiar with configuring your own Solutions, Projects, etc., as it (the Wizard) will do much of the basics for you.


Cheers

Hi,
Autocad .net Wizard is very helpful and easy to deal with than WPF and Windows forms .