Question

Urgent!!! Autocad VBA copy to clipboard

Asked by: PhillO

Hi All

I am in need of some help very quickly to finish a job

I am using autocad 2002 and pdf995 to generate pdf files

I have constructed a VBA program to copy the drawing name to the clipboard since the saving name in pdf995 is malformed

The program sucessfully copyies the name to clipboard ( i have tested this)

However if i tryto plot the drawing using the -plot command, both autocad and pdf995 hangs

It is almost like autocad hasn't released the clipboard and pdf995 is waiting for access. but control is not returned to auocad until pdf995 has done its job - ie circular dependancies ( i think)!!

here is the VBA code

Sub VTC() 'short for SystemVariableToClipboard
   
    toClipboard
   
End Sub

Sub toClipboard() 'short for SystemVariableToClipboard
   
    Dim objectList As New DataObject
    Dim param As String
    Dim parameterArray() As String
    Dim ref As String

    parameterArray() = Split(ThisDrawing.Utility.GetString(False), " ")
    For i = 0 To UBound(parameterArray)
        ref = ref & getSysVar(parameterArray(i))
        If UBound(parameterArray) > 0 Then ref = ref & vbNewLine
    Next i
   
    objectList.SetText ref
    objectList.PutInClipboard
   
End Sub

Private Function getSysVar(varName As String) As String
Dim SysVar As String
Dim i As Integer

On Error Resume Next
SysVar = ThisDrawing.GetVariable(varName)
If Err <> 0 Then
    Err.Clear
    SysVar = varName
ElseIf varName = "DWGNAME" Then 'REMOVE DRAWING FILE EXTENSIOIN IE '.dwg'
    Do
    If Mid(SysVar, Len(SysVar) - i, 1) = "." Then
        SysVar = Left(SysVar, Len(SysVar) - i - 1)
        i = Len(SysVar)
    Else
        i = i + 1
    End If
    Loop While i < Len(SysVar)
End If

getSysVar = SysVar

End Function


and here is how i am invoking it

(DEFUN C:DTC () (COMMAND "-VBARUN" "VTC" "DWGNAME"))

typing dtc to start the copy process

Finally i am using a macro to plot using the -plot command

Both programs work indivually but not together.
some URGENT help would be greatly appreciated

Phill




 

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2006-02-09 at 18:41:16ID21731171
Tags

vba

,

clipboard

,

autocad

,

copy

Topic

CAD & Architecture Software

Participating Experts
1
Points
500
Comments
15

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. AutoCAD Scripts
    I have VB.NET 2003 and AutoCAD 2005. I am wanting to do some batch importing and exporting in .dwg, .dxf, and .3ds. Can somebody point me in the right direction? Matthew
  2. autocad 2005 slow
    Hi since i put autocad 2005 on my pc dell p 4 with 512 mb of ram it works very slow ,autocad 2005 runs very slow on my machine,can i set up autocad that everytimes i open autocad 2005 it purges and delete filters automatically? what i can do to make my autocad 2005 quickest ...
  3. AutoCAD Lite 2006 vs. AutoCAD 2006
    I have a client that is requesting AutoCAD 2006. But all he would use it for is some lite drafting and viewing. The other things he would like to know is how Lite compares to straight AutoCAD when it comes to plotting and opening up AutoCAD files from previous versions.
  4. 3d drawing from autocad to illustrator
    Trying to get a 3d autocad drawing with filename extension of dwg into adobe illustrator. Does anyone know how to do this or if it can be done?
  5. Extract data from AutoCAD drawings
    I'm looking for some kind of library that will let me extract meaningful information from an AutoCAD drawing. Things like the author, copyright, title, revision number, some kind of description / summery of the document, and other tidbits of information that are stored in an ...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: norrin_raddPosted on 2006-02-10 at 07:33:50ID: 15923358

when I run that code the dwg hangs until I hit esc then I get a runtime error at this line:

 parameterArray() = Split(ThisDrawing.Utility.GetString(False), " ")

How are you pasting the name in the plot file dialog?

Try this little tidbit to get your  dwgname var, it works for me

Sub TESTTEXT()
    Dim MyData As DataObject
    Dim dwgname As Variant
    Dim sysvar As String
    sysvar = "dwgname"
    Dim namelen As Long
   
   
    dwgname = ThisDrawing.GetVariable(sysvar)
    namelen = Len(dwgname) - 4
    dwgname = Left(dwgname, namelen)
    Set MyData = New DataObject
    MyData.SetText dwgname
   
    MyData.PutInClipboard
End Sub

 

by: norrin_raddPosted on 2006-02-10 at 07:51:04ID: 15923531

ps, i didnt do any error trapping

 

by: PhillOPosted on 2006-02-10 at 13:43:06ID: 15926965

I actually wanted something that will allow me to copy any system variable to clipboard. for example somethimes i need to use the DWGPREFIX or CTAB but as i understand it i can't get "paramerters" from the command line using pure vba.

what error message did you get?

I already have a function similar to yours but i wanted to make it a bit more flexible

i am just using ctrl-v to past the information


Rgards
Phill

 

by: norrin_raddPosted on 2006-02-10 at 14:10:24ID: 15927221

sorry
"method `getstring' of object `IAcadUtility2' failed"

How are you going to tell your routine which var you want?
 Im not a vba guru by any means, I havent really gotten into parameterarrays and all.
If it was me I'd set up a CASE and have a button for each var you wanted or be able to key it in maybe. You could send the var name using a lisp variable maybe one of the "USER#" ones, I've got codes that do that like:

^C^C(setvar "USERI1" 1) -vbarun;mycode

then use a
dim whatever as string
whatever = thisdrawing.getvariable("user1")
select case whatever

case 1
and so on.

But I'm not sure if thats what you are after.
Be interesting to see how you get it.
I wish autodesk would just suck it up and make pdf's easier to do, dont you?
good luck

 

by: PhillOPosted on 2006-02-11 at 06:33:38ID: 15930526

After *much* experirmation,  it seems that this problem is isolated to pdf995 for some reason

I might have to change pdf wirters

Do you mind if i  have this question deleted?

Phill

 

by: norrin_raddPosted on 2006-02-11 at 19:56:42ID: 15933356

I dont care if you delete the question, but if you do have a solution, post it and you could ask for a  PAQ just in case anyone else has the same issues, instead of deleting it.

But why do you think the problem is isolated to pdf995? acad hung up on me when I ran that code and I dont even have it on that machine. Your code did put the text in the clipboard though so it worked part of the way.

Does the ctrl-v not work after getting  the dwg name after running that code that I posted, or is acad still hanging up on you?

Just so I understand what you are trying to do:
run routine to get dwgname in clipboard (with code able to get other vars)
run macro to plot using pdf995, then paste(ctrl-v) the name when it asks you for filename/location
create file

am I right or am I missing someting?

LIke I said I dont care about the points or if you delete the question or not. But with the popularity of pdf995 you might want to consider the other option.

radd

 

by: PhillOPosted on 2006-02-11 at 20:41:33ID: 15933484

Hi radd

Yes you have it right

i tried a few other printer drivers and all accepted ctrl-v and correctly pasted the file name. With pdf995, i had to kill the save file dialogue box to gain control of autocad.

I already have code similar to yours to get the drawings name. However sometimes i need to include the drawing "PREFIX" variable.

So that is why i used the command line lisp so that i can use a command within autocad to determine which i need at the time. Also by doing this way the function is extensible and can be used by other vba code to do other things.

I am open to other ideas but i thought from "playing around" that the problem was a pdf995 problem that is all

Quite frankly if there is another solution i would be much happier as it is quite a hassal finding other software to replace what i am used to.

phill



 

by: norrin_raddPosted on 2006-02-13 at 07:23:00ID: 15941924

so if you just copy a string of text using ctrl-c and try pasting it in the pdf save dialog(ctrl-v) pdf995 doesnt like that?

are you typing that command line lisp in everytime?

As far as passing a variable (or parameters, I was missunderstading) from lisp to vba you are right it cant be done at the command line. The easiest way that I have found was to set one of the "useri" variables to what you want and then get that variable in vba and use it in a function like I mentioned above.

If you havent already you might look at using the "thisdrawing.utility.getinput" in vba, you might can use that instead of the lisp command line to get which ever variable that you want at the time, but I'm not sure I havent checked it out all the way. there is an example in the help file.


 

by: PhillOPosted on 2006-02-13 at 13:35:04ID: 15945379

pdf995 still hangs.

no other app seems to

Though your tip actually helped to redefine how i'm getting the user input - thanks!!

My revised code:....

Sub VTC() 'short for SystemVariableToClipboard
Dim parameterArray() As String
    Dim keywordList As String
    Dim ui As String
    keywordList = "Keyword1 Keyword2"


    ThisDrawing.Utility.InitializeUserInput 128, keywordList
    ui = ThisDrawing.Utility.GetString(False, "test: ")

   
     toClipboard (ui)
   
End Sub

Sub toClipboard(ui As String) 'short for SystemVariableToClipboard
   
    Dim objectList As New DataObject
    Dim param As String
    Dim parameterArray() As String
    Dim ref As String
   

    parameterArray() = Split(ui, " ")
    For i = 0 To UBound(parameterArray)
        ref = ref & getSysVar(parameterArray(i))
        If UBound(parameterArray) > 0 Then ref = ref & vbNewLine
    Next i
   
    objectList.SetText ref
    objectList.PutInClipboard
   
End Sub

Private Function getSysVar(varName As String) As String
Dim SysVar As String
Dim i As Integer

ThisDrawing.Utility.GetInput
On Error Resume Next
SysVar = ThisDrawing.GetVariable(varName)
If Err <> 0 Then
    Err.Clear
    SysVar = varName
ElseIf varName = "DWGNAME" Then 'REMOVE DRAWING FILE EXTENSIOIN IE '.dwg'
    Do
    If Mid(SysVar, Len(SysVar) - i, 1) = "." Then
        SysVar = Left(SysVar, Len(SysVar) - i - 1)
        i = Len(SysVar)
    Else
        i = i + 1
    End If
    Loop While i < Len(SysVar)
End If

getSysVar = SysVar

End Function


Is there anything a bit wrong with it

 

by: norrin_raddPosted on 2006-02-14 at 07:26:56ID: 15951603

hey Phill,
I used you code here at work late yesterday, and it worked with acrobat and anything else (I dont have pdf995 here), as long as I used all caps when typing in the var I wanted.
 IMHO, I would set up some other way to get the var, like a dropdown box populated with the vars or maybe some 2-3 stroke hot keys, but if you like typing in the whole var name thats up to you, diff strokes for diff folks, you know what I mean? ;)

At home I do have pdf995. I hope you bought the keys that disable that popup crap becuase I didnt and its a royal pain.
Anyway, I found some very interesting things.
If I just ctrl-c something, like highlight some text on this webpage, and ctrl-v in the save dialog it didnt have any problems. If I ran that code and ctrl-v in there, it'd hang, go figure.
But once I restarted acad and tried ctrl-v(without running the code) it would work, pasting what the code putinclipboard the last time.
So that tells me that the pdf995 dialog must not like the way(format maybe?) that the dataobject puts the data in the clipboard at runtime?
But it hangs on you if you just ctrl-v some highlighted text right?
I dont know, if you purchased the keys with support options I'd give them a buzz.
IMO, Something is wrong with there stuff.

I was going to test something last night but ran out of time. I was going to create some text and see if I could get vba to copy it to the clipboard using ctrl-c instead of the databobject somehow, not sure if that is possibe, but it would be a way to test it.

 

by: PhillOPosted on 2006-02-15 at 05:47:46ID: 15960064

Hello once again

I had a bit of a fiddle and it seems to be that the problem is that the code is part of an existing project.

I removed it and put it in a project of its own and it seemed to work as it should

The existing project runs continuously until it is explicitly stopped

So i am guessing that some how a running VBA program must be holding on to a "resource" that is required by pdf995. other printer dirvers must not operate the same????

See what you think.


 

by: norrin_raddPosted on 2006-02-16 at 06:03:01ID: 15971043

must be something like that. one thing Im not sure I tried was to run a vba routine that does something else, then just try to copy/paste something non programmically. try that.

 

by: norrin_raddPosted on 2006-02-24 at 06:52:28ID: 16038715

hey phill,
did you ever come up with anything? perhaps a better pdf maker? bluebeam looks interesting, got a link in an augi newsletter, its not free but not as high as adobe:

http://www.bluebeam.com/web03/products/products.asp

 

by: PhillOPosted on 2006-02-24 at 07:47:38ID: 16039202

Hi Norrin

I have been madly looking at different pdf programs but none seem to be as good as acrobat for editing. But i certainly will have a further look at this one. it *looks* interesing but you never know until its tested.

I think that the problem lies in the clash i stated above. thats the best i've figured out.

In any case, i will accept your last entry as the "correct" response because i am greatful for you help and thru this discourse i have identified the problems and realised that i have to get a new pdf printer or use my vba program does its job and then terminates.

Sorry. I hope this makes sense it is 3am here and i rarely make sense at this time of the morning

Once again thanks. I am downloading this blue beam to check it out

Phill

 

by: norrin_raddPosted on 2006-02-24 at 08:22:11ID: 16039606

thanks for the points and I'm sorry we couldnt make it work with your current software. let us know how you like the blue beam stuff.
Thanks

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...