Support Folder Add

Support Folder Add

k005
Advisor Advisor
2,548 Views
18 Replies
Message 1 of 19

Support Folder Add

k005
Advisor
Advisor

Hi All !

 

My aim is to make an addition to AutoCAD support folders. But I want to do this with command.

sample :

 

 E:\BlockRAM

 

 

How can I do that ?

0 Likes
Accepted solutions (1)
2,549 Views
18 Replies
Replies (18)
Message 2 of 19

R.Gerritsen4967
Advocate
Advocate

Look around in this topic. Especially this post. I'm sure you will find what you need...

Message 3 of 19

k005
Advisor
Advisor

 

I took a look at the codes here, I think it might be.

 

I'll try... Thank you.

 

 

* I'm sure too.. 🙂

0 Likes
Message 4 of 19

Ed__Jobe
Mentor
Mentor

Here is my solution.

        Private Sub AppendSupportPath(ByVal FilePath As String)
            Try
                Dim app As AcadApplication = Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication
                Dim files As AcadPreferencesFiles = app.Preferences.Files
                Dim ary As String() = files.SupportPath.Split(";")
                Dim bln As Boolean = False
                '  Check to see if its already added.
                For Each Str As String In ary
                    If Str = FilePath Then bln = True
                Next
                '   If not, add it.
                If bln = False Then
                    files.SupportPath = files.SupportPath.ToString & ";" & FilePath.ToString
                End If

            Catch ex As Autodesk.AutoCAD.Runtime.Exception

            End Try
        End Sub

        Private Sub PrependSupportPath(ByVal FilePath As String)
            Try
                Dim app As AcadApplication = Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication
                Dim files As AcadPreferencesFiles = app.Preferences.Files
                Dim ary As String() = files.SupportPath.Split(";")
                Dim bln As Boolean = False
                '  Check to see if its already added.
                For Each Str As String In ary
                    If Str = FilePath Then bln = True
                Next
                '   If not, add it.
                If bln = False Then
                    files.SupportPath = FilePath.ToString & ";" & files.SupportPath.ToString
                End If

            Catch ex As Autodesk.AutoCAD.Runtime.Exception

            End Try
        End Sub

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 5 of 19

k005
Advisor
Advisor

Thanks for the code.

 

But where do I add the E:\blocksRAM path here?

 

i didn't see it. and i have to do it with C# codes.

0 Likes
Message 6 of 19

Ed__Jobe
Mentor
Mentor

It's a sub. You supply the path string in the argument.

 

 

'some other sub
   AppendSupportPath("E:\blocksRAM")
'continue work

 

 

Note that these functions are in VB. You may need to convert them to C#. They are from my first dll which I haven't converted to C#. They also handle inserting a ; between paths. Just supply the path you want. If you want to add multiple paths, just call the sub multiple times.

 

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

Message 7 of 19

k005
Advisor
Advisor

I understand now. Thank you.

 

* I wanted to add this to my DVB file, got some errors.

0 Likes
Message 8 of 19

norman.yuan
Mentor
Mentor

Well, your code is VBA code, not .NET/VB.NET. So, you might as well ask the question in VBA forum in future.

 

Anyway, VBA (and old classical VB) does not support "Try....Catch...", nor Array in VBA supports "For Each...Next". (Hint: you cannot copy VB.NET code into AutoCAD's VBA and expect it to work).

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 9 of 19

k005
Advisor
Advisor
Yes I know.

But I don't know VBA exactly... There were small programs I prepared before. I thought it might work because the codes are similar...

Even though it works, I need C# codes, Sir.

Thank you.
0 Likes
Message 10 of 19

k005
Advisor
Advisor

Yes I know.

But I don't know VBA exactly... There were small programs I prepared before. I thought it might work because the codes are similar...

Even though it works, I need C# codes, Sir.

Thank you.

0 Likes
Message 11 of 19

Ed__Jobe
Mentor
Mentor
Accepted solution

Here it is in C#.

 

using System;
using System.Windows.Forms;
using Autodesk;
using Autodesk.AutoCAD.ApplicationServices;
using acApp = Autodesk.AutoCAD.ApplicationServices.Application;
using Autodesk.AutoCAD.Interop;

namespace TID_
{
    public class Helper
    {
        private void AppendSupportPath(string FilePath)
        {
            try
            {
                AcadApplication app = acApp.AcadApplication;
                AcadPreferencesFiles files = app.Preferences.Files;
                string[] ary = files.SupportPath.Split(';');
                bool bln = false;
                //  Check to see if its already added.
                foreach (String Str in ary)
            {
                    if (Str == FilePath)
                    {
                        bln = true;
                    };
                };
                //   If not, add it.
                if (bln == false)
                {
                    files.SupportPath = files.SupportPath + ";" + FilePath;
                };
            }
            catch (Autodesk.AutoCAD.Runtime.Exception ex)
            {
                MessageBox.Show("Error Occured in AppendSupportPath. " + ex.Message + ", ", "AppendSupportPath Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }


        private void PrependSupportPath(string FilePath)
        {
            try
            {
                AcadApplication app = acApp.AcadApplication;
                AcadPreferencesFiles files = app.Preferences.Files;
                string[] ary = files.SupportPath.Split(';');
                bool bln = false;
                //  Check to see if its already added.
                foreach (String Str in ary)
            {
                    if (Str == FilePath)
                    {
                        bln = true;
                    };
                };
                //   If not, add it.
                if (bln == false)
                {
                    files.SupportPath = files.SupportPath = FilePath + ";" + files.SupportPath;
                };
            }
            catch (Autodesk.AutoCAD.Runtime.Exception ex)
            {
                MessageBox.Show("Error Occured in PrependSupportPath. " + ex.Message + ", ", "PrependSupportPath Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    }
}

 

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

Message 12 of 19

k005
Advisor
Advisor

 I'm getting errors in these parts., I'm trying to fix it...

 

 

AcadApplication app = Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication;

0 Likes
Message 13 of 19

Ed__Jobe
Mentor
Mentor

Did you add a reference to Autodesk.AutoCAD.Interop? Any time you have a 'using' statement, you have to first reference the appropriate library. It's like trying to order a burger at Subway. They have to have it before you can use it.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 14 of 19

k005
Advisor
Advisor

Yes I know. i added that too. But there are still errors.

 

 

0 Likes
Message 15 of 19

Ed__Jobe
Mentor
Mentor

Did you include the using statement I had? Do you have the standard references to  the autocad dll's? ...and their corresponding using statements?

 

I also noticed some typos. Stand by.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 16 of 19

k005
Advisor
Advisor

Yes there is.

 

But it needs to be simplified a little more.

 

* So how can we do this more simply?

 

for example ;

 

Aapp.Application.SetSystemVariable("Lispsys", 0); etc..

 

our process is just to introduce a folder.

 

This shouldn't require a lot of code. Because the process is too short...

0 Likes
Message 17 of 19

Ed__Jobe
Mentor
Mentor

I revised the code the previous post.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

Message 18 of 19

Ed__Jobe
Mentor
Mentor

@k005 wrote:

Yes there is.

 

But it needs to be simplified a little more.

 

* So how can we do this more simply?

 

for example ;

 

Aapp.Application.SetSystemVariable("Lispsys", 0); etc..

 

our process is just to introduce a folder.

 

This shouldn't require a lot of code. Because the process is too short...


There is only one way to set the search file paths. It is stored as a semi-colon delimited string in the application Preferences object, which is only accessible by COM.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 19 of 19

k005
Advisor
Advisor

Yes it is OK. Thank you very much., 🤗

0 Likes