Work on vs2008 C#, Need help to connect with autocad 2010, I follow the following steps to connect but it gives me an error.
I have to add a reference, so I go to references>>add reference>>[COM TAB]>>Autocad 2010 type library>>[OK]
I use two libraries:
using Autodesk.AutoCAD.Interop;
using Autodesk.AutoCAD.Interop.Common;
And then I use the following code to connect with AutoCAD 2010:
namespace Sample_CSharp_Acad_connect
{
class Program
{
private static IAcadApplication oAcadApp = null;
private static string sAcadID = "AutoCAD.Application.18";
static void Main()
{
try //get a running AutoCAD instance if avaialbale
{
oAcadApp = (IAcadApplication)System.Runtime.InteropServices.Marshal.GetActiveObject(sAcadID);
}
catch(Exception) //none found so start a new instance
{
System.Type AcadProg = System.Type.GetTypeFromProgID(sAcadID);
oAcadApp = (IAcadApplication)System.Activator.CreateInstance(AcadProg);
}
if (oAcadApp != null)
{
oAcadApp.Visible = true; //could leave this false to hide Acad from the user
//do whatever with Acad
//oAcadApp.Quit();
}
}
}
Error message : error in getting object class COM for component CLSID
COM? Don't do it.
AutoCAD has a .NET API. See http://usa.autodesk.com/adsk/servlet/index?id=1911627&siteID=123112 for resources from Autodesk. Also see the wiki here for more info and links galore: https://stackoverflow.com/tags/autocad/info
How do you run this code? Is it an exe file? As far as I know, it is not so easy to control AutoCAD using an external progam. There are often lizening issues which prevent such operations.
It might be easier to access AutocAD functionality using a DLL. In that case the object model of AutoCAD can be accessed directly:
Dim theApp as Autodesk.AutoCAD.Interop.AcadApplications = Autodesk.AutoCAD.Interop.AcadApplication()
Debug.Print(theApp.Caption)
The SDK contains a lot of samples for DLLs which can be loaded into AutoCAD.
And: If it isn't really necessary, consider using .NET!
Related
I am trying to communicate with my chatbot via a Windows Form App (using C#). I have installed the SDK into Visual Studio, but I am having trouble using it. I have read through all the documentation, including on GitHub, however, because this is my first time using the SDK, I am quite confused about how to get it to work. At this point, I simply want to be able to send a "Message" and read the chatbot's response.
Which namespaces do I have to include (i.e. "using IBM.Watson...")? Because I have tried authenticating but am getting the error: "namespace AssistantService could not be found", as per the IAM authentication in dotnet guide on GitHub. Also, what is an "_assistant" object and how to I create one, the docs don't explain this so I keep getting the error "_assistant does not exist in the current context..."
This is the link that to the SDK I am following: https://github.com/watson-developer-cloud/dotnet-standard-sdk
I am trying to authenticate with the instructions at that link but am not succeeding. I am trying to use these instructions to call the Watson Assistant: https://github.com/watson-developer-cloud/dotnet-standard-sdk/tree/development/src/IBM.WatsonDeveloperCloud.Assistant.v1
****************UPDATE*****************
using System.Windows.Forms;
using IBM.WatsonDeveloperCloud.Assistant.v1.Model;
using IBM.WatsonDeveloperCloud.Assistant.v1;
using IBM.WatsonDeveloperCloud.Util;
namespace Watson_Assistant_Test
{
public partial class Form1 : Form
{
AssistantService _assistant;
string[] _questionArray = { "Hello there" };
public Form1()
{
TokenOptions iamAssistantTokenOptions = new TokenOptions()
{
IamApiKey = "Y....H",
IamUrl = "https://gateway-syd.watsonplatform.net/assistant/api"
};
_assistant = new AssistantService(iamAssistantTokenOptions, "2018-07-10");
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
MessageRequest messageRequest = new MessageRequest()
{
Input = new InputData()
{
Text = _questionArray[0]
}
};
var result = _assistant.Message("d...5", messageRequest);
label1.Text = result.ResponseJson.ToString();
}
}
}
I think I am still not creating the AssistantObject correctly. I am getting this error: ServiceResponseException: The API query failed with status code NotFound: Not Found.
Thanks, Harry
[I am not a C# developer and have not used that SDK, but... :)]
There is a small sample as part of the SDK that works with the car dashboard example. Because of the renaming of Watson Conversation to Watson Assistant it is still using the old object names (both work).
The code uses this namespace:
using IBM.WatsonDeveloperCloud.Assistant.v1.Model
Based on the code itself it checks for the following parts of TokenOptions:
IamApiKey
IamAccessToken
ServiceUrl
My guess is that you have to rename IamUrl to ServiceUrl in your code.
I created some add-in for excel in C#. In it is one public class for using in VBA. On my machine all works ok. When I install add-in on tester computer (I'm using InstallShield 2015 Limited Edition for Visual Studio to create setup file) I can't set object.
C# code
using System;
using Excel = Microsoft.Office.Interop.Excel;
using System.Runtime.InteropServices;
using Microsoft.Win32;
namespace PMTAddin
{
[Guid("B2350EC1-522E-4B75-BB02-86BB0FD1A60E")]
[ClassInterface(ClassInterfaceType.AutoDual)]
[ComVisible(true)]
public class PublicClass
{
public void test()
{
System.Windows.Forms.MessageBox.Show(
"test."
, "test"
, System.Windows.Forms.MessageBoxButtons.OK
, System.Windows.Forms.MessageBoxIcon.Error
);
}
private int GetWorksheetID(Excel.Workbook wb, string worksheetName)
{
int result = 0;
foreach (Excel.Worksheet ws in wb.Worksheets)
{
if (ws.Name == worksheetName)
{
result = ws.Index;
break;
}
}
return result;
}
[ComRegisterFunctionAttribute]
public static void RegisterFunction(Type type)
{
Registry.ClassesRoot.CreateSubKey(GetSubKeyName(type, "Programmable"));
RegistryKey key = Registry.ClassesRoot.OpenSubKey(GetSubKeyName(type, "InprocServer32"), true);
key.SetValue("", System.Environment.SystemDirectory + #"\mscoree.dll", RegistryValueKind.String);
}
[ComUnregisterFunctionAttribute]
public static void UnregisterFunction(Type type)
{
Registry.ClassesRoot.DeleteSubKey(GetSubKeyName(type, "Programmable"), false);
}
private static string GetSubKeyName(Type type, string subKeyName)
{
System.Text.StringBuilder s = new System.Text.StringBuilder();
s.Append(#"CLSID\{");
s.Append(type.GUID.ToString().ToUpper());
s.Append(#"}\");
s.Append(subKeyName);
return s.ToString();
}
}
}
In VBA project I checked reference to it on the list. It calls PMT.
VBA
Sub dsf()
Dim o As PMT.PublicClass
Set o = New PMT.PublicClass 'at this lane on other computer I got error 429. On my computer all work smoothly and method test is running.
o.test
End Sub
I thought that maybe it was something .NET Framework, but it is installed. Any ideas?
EDIT:
I create two diffrent version for bittnes, but the same error.
But I found some new info. In registry on my computer it looks like this
and on tester machine it looks like this
There are no CodeBase value... Do you think this is the problem? If it is, how I need to modify RegisterFunction method to correct this?
After long seeking I found the solution. It's kind of partial, because for 64 bit Excel we need to register library manually (maybe someone knows, how to add bat file to installation file).
I found the answer on this site.
While creating Install Shield instalation file we need to do two things.
Add .tlb file to application files (this step was done by me, before posting on stackoverflow)
Click right on project.Primary output file and choose properities like in screenshot (for *.tlb file we need to check the same, but without "COM Interop")
Without this the installer will not properlly register add-in in registry.
Install file created like this would register add-in for 32-bit excel only. If you want to use it also in 64-bit Excel you need to register library manually. I created simple bat file like this:
c:
cd C:\Windows\Microsoft.NET\Framework64\v4.0.30319
regasm.exe "[pathToDLL]\AddInName.dll" /tlb:"[pathToDLL]\AddInName.tlb" /codebase
pause
Remember, that you need to run it with admin rights.
I have a WPF C# Application. I'm using a Sybase.PowerBuilder.WPF.Controls.DataWindow, but I don't know how to use SetTransObject.
This is some of my code:
using Sybase.PowerBuilder.WPF.Controls;
partial class xxx
{
public xxx()
{
Sybase.PowerBuilder.WPF.Controls.DataWindow DW_1 =
new Sybase.PowerBuilder.WPF.Controls.DataWindow();
DW_1.DataObject = "eee";
DW_1.SetTransObject();
}
}
That control really isn't intended to be used outside of the PowerBuilder.Net environment. I can imagine that you'd run into a number of issues trying to use it directly from VS.Net. In this particular instance, SetTransObject takes a PowerBuilder.Net database connection object. You might be best service by creating a visual user object in PowerBuilder.Net and then using that from VS.Net.
The visio application object can be controlled in c# programs via the assembly Microsoft.Office.Interop.Visio. The documentation of the visio application object 2010 is showing the property CurrentEdition:
http://office.microsoft.com/en-us/visio-help/HV080350129.aspx
However in my small c# application the property does not exist - although a reference to Microsoft.Office.Interop.Visio has been created. Now my question is how this property can be made accessible for an external application? In case the Interop assemblies are restricted do you know another assembly to get this done? Thanks!
using System;
namespace VisioTest
{
class Program
{
static void Main(string[] args)
{
Microsoft.Office.Interop.Visio.Application visioApp;
visioApp = new Microsoft.Office.Interop.Visio.Application();
if (visioApp.Application.CurrentEdition == Microsoft.Office.Interop.Visio.VisEdition.visEditionStandard)
{
// standard edition etc.
}
}
}
}
I am developing an add in for C# that would only be used during debugging. Once instantiated, my add in needs to find all instances of a specific class or interface to display a graph about the data found.
How exactly can I find or access these objects in my extension? I have access to the DTE2 application object in my extension, but I'm not sure how to search the actual code being debugged by VS. I'm thinking I might somehow be able to use Reflection, but I'm not sure where to look.
Thanks.
I've implemented a plugin that searches through dlls in a given directory and finds classes that implement a particular interface. Below is the class I used to do this:
public class PlugInFactory<T>
{
public T CreatePlugin(string path)
{
foreach (string file in Directory.GetFiles(path, "*.dll"))
{
foreach (Type assemblyType in Assembly.LoadFrom(file).GetTypes())
{
Type interfaceType = assemblyType.GetInterface(typeof(T).FullName);
if (interfaceType != null)
{
return (T)Activator.CreateInstance(assemblyType);
}
}
}
return default(T);
}
}
All you have to do is initialize this class with something like this:
PluginLoader loader = new PlugInFactory<InterfaceToSearchFor>();
InterfaceToSearchFor instanceOfInterface = loader.CreatePlugin(AppDomain.CurrentDomain.BaseDirectory);
This type of operation isn't really possible from a Visual Studio plugin. The object alive when debugging live in the debugee process while your add-in is running in the Visual Studio process. It's not possible to access arbitrary objects across process boundaries in .Net.