Author Topic: Next and Previous dwg in directory  (Read 8146 times)

0 Members and 1 Guest are viewing this topic.

GDF

  • Water Moccasin
  • Posts: 2081
Re: Next and Previous dwg in directory
« Reply #15 on: March 19, 2008, 05:05:32 PM »
Tim

Work just fine on a local drive. Still can't get it to work off of the server drive.
Man your routine is fast. LOVE IT.

This now works:
Code: [Select]
Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\SOFTWARE\Autodesk\AutoCAD\R17.1\ACAD-6001:409\Applications\NextPrev17\Groups]
"Support"="Support"


[HKEY_CURRENT_USER\SOFTWARE\Autodesk\AutoCAD\R17.1\ACAD-6001:409\Applications\NextPrev17]
"DESCRIPTION"="Next Previous Drawing in the Directory"
"LOADCTRLS"=dword:00000004
"LOADER"="C:\\Arch_Custom\\Support\\NextPrev17.dll"
"MANAGED"=dword:00000001

[HKEY_CURRENT_USER\SOFTWARE\Autodesk\AutoCAD\R17.1\ACAD-6001:409\Applications\NextPrev17\Commands]
"MyNext"="MyNext"
"MyPrevious"="MyPrevious"

Gary
« Last Edit: March 19, 2008, 05:17:02 PM by Gary Fowler »
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Next and Previous dwg in directory
« Reply #16 on: March 19, 2008, 05:13:21 PM »
I don't use network drives for any programs, as I'm the only one using them.

Glad you like Gary.

If I find out anything helpful about network drives and .Net I will let you know.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

GDF

  • Water Moccasin
  • Posts: 2081
Re: Next and Previous dwg in directory
« Reply #17 on: March 20, 2008, 03:42:25 PM »
I don't use network drives for any programs, as I'm the only one using them.

Glad you like Gary.

If I find out anything helpful about network drives and .Net I will let you know.

Tim

So far no problems, works perfectly.
Have you fiqured out why a network location will not work?

Also would it be possible to close the last drawing while proceeding to the next...similar to the way the old lisp routine worked?
Only want two drawing open at any one time.

Gary
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Next and Previous dwg in directory
« Reply #18 on: March 20, 2008, 03:50:20 PM »
I don't use network drives for any programs, as I'm the only one using them.

Glad you like Gary.

If I find out anything helpful about network drives and .Net I will let you know.

Tim

So far no problems, works perfectly.
Have you fiqured out why a network location will not work?

Also would it be possible to close the last drawing while proceeding to the next...similar to the way the old lisp routine worked?
Only want two drawing open at any one time.

Gary

The network issue is on of security.  By default network .Net programs are not trusted.  To fix it you have to give the network drive (or folders within) a higher trust level.  Some say not the best.  The other way is to strongly name the dll.  I've see some pages on how to do this, but it will be different per site, so your whole site would have one number, and my another, so I'm not sure how you would want to do it off the network.

As far as closing the drawing it's called in, I don't think that would be a problem at all.  Would you want it to prompt you to save if needs be?  Or just discard the changes?  I might be able to get to this today to test.

One work around is to copy the .Net dll to all work stations.  Then define a lisp routine with the same name as the two functions within the dll.  Within the lisp routines call netload to load the dll.  Since commands defined within dll have a higher priority than lisp routines, the lisp routines will only work once per session.  I think there was a post about this in the .Net forum, and it works here.

Edit: Found thread about lisp.
« Last Edit: March 20, 2008, 03:54:12 PM by T.Willey »
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

GDF

  • Water Moccasin
  • Posts: 2081
Re: Next and Previous dwg in directory
« Reply #19 on: March 20, 2008, 04:09:55 PM »
Tim

As far as closing the drawing it's called in, I don't think that would be a problem at all.  Would you want it to prompt you to save if needs be?  Or just discard the changes?  I might be able to get to this today to test.

No prompt needed, if we make any changes we would save them before using the "next" or "previous" commands. This way we would only have a max of two drawings open at a time.

As far as having the dll on the network, we can live with it on the local drive, down loaded to each workstation.

As much as we use this routine, it has been a great time saver. The old lisp routine was just too prone to crashing.

Thanks for all of your hard work and supporting the swamp.

Gary
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Next and Previous dwg in directory
« Reply #20 on: March 20, 2008, 05:05:46 PM »
Here is the quick and dirty way.  I'll do some more research to figure out a better way.

You're welcome.  As far as theSwamp goes, I'm just happy to have a place where I can learn, and in turn help out others.
Code: [Select]
/*
 * Created by SharpDevelop.
 * User: Tim Willey
 * Date: 3/18/2008
 * Time: 4:17 PM
 *
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using System.IO;
using System.Collections;
using System.Windows.Forms;

using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;

using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;

[assembly: CommandClass (typeof (Test.OpenNextPrevious))]

namespace Test
{
/// <summary>
/// Description of OpenNextPrevious.
/// </summary>


class MyStringCompare {

public MyStringCompare () {}

public static int Compare (object obj1, object obj2) {
string str1 = (string)obj1, str2 = (string)obj2;
int i1 = 0,
i2 = 0,
CompareResult,
l1 = str1.Length,
l2 = str2.Length,
tempI1,
tempI2;
string s1, s2;
bool b1, b2;

while (true) {
b1 = Char.IsDigit(str1, i1);
b2 = Char.IsDigit(str2, i2);
if ( !b1 && b2 )
return -1;
if ( b1 && !b2 )
return 1;
if (b1 && b2) {
FindLastDigit(str1, ref i1, out s1);
FindLastDigit(str2, ref i2, out s2);
tempI1 = Convert.ToInt32(s1);
tempI2 = Convert.ToInt32(s2);
if ( tempI1.Equals(tempI2) )
CompareResult = 0;
else if (tempI1 < tempI2)
CompareResult = -1;
else
CompareResult = 1;
if ( !CompareResult.Equals(0) )
return CompareResult;
}
else {
FindLastLetter(str1, ref i1, out s1);
FindLastLetter(str2, ref i2, out s2);
CompareResult = string.Compare(s1, s2);
if ( !CompareResult.Equals(0) )
return CompareResult;
}
if (l1 <= i1) {
if (l2 <= i2) {
return 0;
}
else {
return -1;
}
}
if (l2 <= i2) {
if (l1 < i1) {
return 0;
}
else {
return 1;
}
}
}
}
private static void FindLastLetter (string MainStr, ref int i, out string OutStr) {
int StartPos = i;
int StrLen = MainStr.Length;
++i;
while ( i < StrLen && !Char.IsDigit(MainStr, i) )
++i;
OutStr = MainStr.Substring(StartPos, i - StartPos);
}
private static void FindLastDigit (string MainStr, ref int i, out string OutStr) {
int StartPos = i;
int StrLen = MainStr.Length;
++i;
while ( i < StrLen && Char.IsDigit(MainStr, i) )
++i;
OutStr = MainStr.Substring(StartPos, i - StartPos);
}
}
public class OpenNextPrevious
{
[CommandMethod("MyNext", CommandFlags.Session)]
public void OpenNext()
{
string DwgPath = AcadApp.GetSystemVariable("DwgPrefix") as string;
string DwgName = AcadApp.GetSystemVariable("DwgName") as string;
Document Doc = AcadApp.DocumentManager.MdiActiveDocument;
Doc.CloseAndDiscard();
OpenDrawing(1, DwgPath, DwgName);
}
[CommandMethod("MyPrevious", CommandFlags.Session)]
public void OpenPrevious()
{
string DwgPath = AcadApp.GetSystemVariable("DwgPrefix") as string;
string DwgName = AcadApp.GetSystemVariable("DwgName") as string;
Document Doc = AcadApp.DocumentManager.MdiActiveDocument;
Doc.CloseAndDiscard();
OpenDrawing(-1, DwgPath, DwgName);
}
public void OpenDrawing (int ToOpen, string DwgPath, string DwgName) {

Document Doc = null;
DocumentCollection DocCol = AcadApp.DocumentManager;
//string DwgPath = AcadApp.GetSystemVariable("DwgPrefix") as string;
//string DwgName = AcadApp.GetSystemVariable("DwgName") as string;
string FullPath = DwgPath + DwgName;
string[] DwgList = Directory.GetFiles(DwgPath, "*.dwg");
Array.Sort(DwgList, new MyStringCompare1());
int cNum = Array.IndexOf(DwgList, FullPath);

if ( ToOpen.Equals(1) ) {
if ( cNum.Equals(DwgList.Length - 1) ) {
MessageBox.Show("Already at the last drawing in the folder.", "Not really an error.");
return;
}
}
else {
if ( cNum.Equals(0) ) {
MessageBox.Show("Already at the first drawing in the folder.", "Not really an error.");
return;
}
}

string Path = DwgList[cNum + ToOpen];

foreach (Document doc in DocCol) {
if (string.Compare(Path, doc.Name, true).Equals(0)) {
Doc = doc;
break;
}
}
if (Doc != null)
DocCol.MdiActiveDocument = Doc;
else
DocCol.Open(Path, false);
}

public class MyStringCompare1 : IComparer {
public MyStringCompare1 () {}
public int Compare (object x, object y) {
return MyStringCompare.Compare( x,y );
}
}
}
}
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

GDF

  • Water Moccasin
  • Posts: 2081
Re: Next and Previous dwg in directory
« Reply #21 on: March 20, 2008, 05:30:28 PM »
AWESOME
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

T.Willey

  • Needs a day job
  • Posts: 5251
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

GDF

  • Water Moccasin
  • Posts: 2081
Re: Next and Previous dwg in directory
« Reply #23 on: May 20, 2011, 04:33:57 PM »
Tim

I know this is an old subject. I just noticed that the routine next and previous is case sensitive in opening the next drawing in a folder.
For example:

A7.01
A7.02
a7.03
A7.04

The routine would skip over the lowercase a7.03

Can this be easily fixed? Or do I need to rename my drawing to always be uppercase first letters.

Gary
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Next and Previous dwg in directory
« Reply #24 on: May 23, 2011, 10:12:51 AM »
It might be an easy fix, I don't know really.  If I have time I'll look at the sorting function, and see what is happening.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

GDF

  • Water Moccasin
  • Posts: 2081
Re: Next and Previous dwg in directory
« Reply #25 on: May 23, 2011, 10:36:49 AM »
It might be an easy fix, I don't know really.  If I have time I'll look at the sorting function, and see what is happening.

Thanks
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Next and Previous dwg in directory
« Reply #26 on: May 23, 2011, 11:07:53 AM »
Was a really simple fix.  Edited one line in the sort function to ignore case, and then recompile.

Edit:  Forgot to mention that I added two other functions, so now you can close the current drawing when switching to the next/previous drawing.

Code: [Select]
/*
 * Created by SharpDevelop.
 * User: Tim Willey
 * Date: 3/18/2008
 * Time: 4:17 PM
 *
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using System.IO;
using System.Collections;
using System.Windows.Forms;

using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;

using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;

[assembly: CommandClass (typeof (Test.OpenNextPrevious))]

namespace Test
{
/// <summary>
/// Description of OpenNextPrevious.
/// </summary>


class MyStringCompare {

public MyStringCompare () {}

public static int Compare (object obj1, object obj2) {
string str1 = (string)obj1, str2 = (string)obj2;
int i1 = 0,
i2 = 0,
CompareResult,
l1 = str1.Length,
l2 = str2.Length,
tempI1,
tempI2;
string s1, s2;
bool b1, b2;

while (true) {
b1 = Char.IsDigit(str1, i1);
b2 = Char.IsDigit(str2, i2);
if ( !b1 && b2 )
return -1;
if ( b1 && !b2 )
return 1;
if (b1 && b2) {
FindLastDigit(str1, ref i1, out s1);
FindLastDigit(str2, ref i2, out s2);
tempI1 = Convert.ToInt32(s1);
tempI2 = Convert.ToInt32(s2);
if ( tempI1.Equals(tempI2) )
CompareResult = 0;
else if (tempI1 < tempI2)
CompareResult = -1;
else
CompareResult = 1;
if ( !CompareResult.Equals(0) )
return CompareResult;
}
else {
FindLastLetter(str1, ref i1, out s1);
FindLastLetter(str2, ref i2, out s2);
[color=red]CompareResult = string.Compare(s1, s2, true);[/color]
if ( !CompareResult.Equals(0) )
return CompareResult;
}
if (l1 <= i1) {
if (l2 <= i2) {
return 0;
}
else {
return -1;
}
}
if (l2 <= i2) {
if (l1 < i1) {
return 0;
}
else {
return 1;
}
}
}
}
private static void FindLastLetter (string MainStr, ref int i, out string OutStr) {
int StartPos = i;
int StrLen = MainStr.Length;
++i;
while ( i < StrLen && !Char.IsDigit(MainStr, i) )
++i;
OutStr = MainStr.Substring(StartPos, i - StartPos);
}
private static void FindLastDigit (string MainStr, ref int i, out string OutStr) {
int StartPos = i;
int StrLen = MainStr.Length;
++i;
while ( i < StrLen && Char.IsDigit(MainStr, i) )
++i;
OutStr = MainStr.Substring(StartPos, i - StartPos);
}
}
public class OpenNextPrevious
{
[CommandMethod("MyNext", CommandFlags.Session)]
public void OpenNext()
{
string DwgPath = AcadApp.GetSystemVariable("DwgPrefix") as string;
string DwgName = AcadApp.GetSystemVariable("DwgName") as string;
OpenDrawing(1, DwgPath, DwgName, false);
}
[CommandMethod("MyNextAndCloseCurrent", CommandFlags.Session)]
public void OpenNextAndCloseCurrent()
{
string DwgPath = AcadApp.GetSystemVariable("DwgPrefix") as string;
string DwgName = AcadApp.GetSystemVariable("DwgName") as string;
//AcadApp.DocumentManager.MdiActiveDocument.CloseAndDiscard();
OpenDrawing(1, DwgPath, DwgName, true);
}
[CommandMethod("MyPrevious", CommandFlags.Session)]
public void OpenPrevious()
{
string DwgPath = AcadApp.GetSystemVariable("DwgPrefix") as string;
string DwgName = AcadApp.GetSystemVariable("DwgName") as string;
OpenDrawing(-1, DwgPath, DwgName, false);
}
[CommandMethod("MyPreviousAndCloseCurrent", CommandFlags.Session)]
public void OpenPreviousAndCloseCurrent()
{
string DwgPath = AcadApp.GetSystemVariable("DwgPrefix") as string;
string DwgName = AcadApp.GetSystemVariable("DwgName") as string;
//AcadApp.DocumentManager.MdiActiveDocument.CloseAndDiscard();
OpenDrawing(-1, DwgPath, DwgName, true);
}
public void OpenDrawing (int ToOpen, string DwgPath, string DwgName, bool CloseCurrent) {

Document Doc = null;
DocumentCollection DocCol = AcadApp.DocumentManager;
//string DwgPath = AcadApp.GetSystemVariable("DwgPrefix") as string;
//string DwgName = AcadApp.GetSystemVariable("DwgName") as string;
string FullPath = DwgPath + DwgName;
string[] DwgList = Directory.GetFiles(DwgPath, "*.dwg");
MyStringCompare1 msc1 = new MyStringCompare1();
Array.Sort(DwgList, msc1);
int cNum = Array.IndexOf(DwgList, FullPath);

if ( ToOpen.Equals(1) ) {
if ( cNum.Equals(DwgList.Length - 1) ) {
MessageBox.Show("Already at the last drawing in the folder.", "Not really an error.");
return;
}
}
else {
if ( cNum.Equals(0) ) {
MessageBox.Show("Already at the first drawing in the folder.", "Not really an error.");
return;
}
}

if ( CloseCurrent )
AcadApp.DocumentManager.MdiActiveDocument.CloseAndDiscard();

string Path = DwgList[cNum + ToOpen];

foreach (Document doc in DocCol) {
if (string.Compare(Path, doc.Name, true).Equals(0)) {
Doc = doc;
break;
}
}
if (Doc != null)
DocCol.MdiActiveDocument = Doc;
else
DocCol.Open(Path, false);
}
}
}
« Last Edit: May 23, 2011, 11:11:21 AM by T.Willey »
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

GDF

  • Water Moccasin
  • Posts: 2081
Re: Next and Previous dwg in directory
« Reply #27 on: May 23, 2011, 11:28:19 AM »
Thanks Tim

Is this one compatable for all versions? Just to be sure I renamed it to NextPrev18.dll

The last one I used this to load it: NextPrev18.reg

Code: [Select]
Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\SOFTWARE\Autodesk\AutoCAD\R18.0\ACAD-8001:409\Applications\NextPrev18\Groups]
"Support"="Support"


[HKEY_CURRENT_USER\SOFTWARE\Autodesk\AutoCAD\R18.0\ACAD-8001:409\Applications\NextPrev18]
"DESCRIPTION"="Next Previous Drawing in the Directory"
"LOADCTRLS"=dword:00000004
"LOADER"="C:\\Arch_Custom\\Support\\NextPrev18.dll"
"MANAGED"=dword:00000001

[HKEY_CURRENT_USER\SOFTWARE\Autodesk\AutoCAD\R18.0\ACAD-8001:409\Applications\NextPrev18\Commands]
"MyNext"="MyNext"
"MyPrevious"="MyPrevious"


Works great Tim, thanks again.
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Next and Previous dwg in directory
« Reply #28 on: May 23, 2011, 11:31:01 AM »
It should be, as I don't think there is anything specific to any version.  Just know that it will not save the current drawing if you use one of the new commands.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.