PhillO
asked on
Urgent!!! Autocad VBA copy to clipboard
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(va rName)
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
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.
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(va
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
ps, i didnt do any error trapping
ASKER
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
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
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("u ser1")
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
"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("u
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
ASKER
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
I might have to change pdf wirters
Do you mind if i have this question deleted?
Phill
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
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
ASKER
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
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
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.getin put" 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.
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.getin
ASKER
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.Initia lizeUserIn put 128, keywordList
ui = ThisDrawing.Utility.GetStr ing(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.GetInp ut
On Error Resume Next
SysVar = ThisDrawing.GetVariable(va rName)
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
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.Initia
ui = ThisDrawing.Utility.GetStr
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.GetInp
On Error Resume Next
SysVar = ThisDrawing.GetVariable(va
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
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.
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.
ASKER
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.
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
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
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
Thanks
parameterArray() = Split(ThisDrawing.Utility.
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(sy
namelen = Len(dwgname) - 4
dwgname = Left(dwgname, namelen)
Set MyData = New DataObject
MyData.SetText dwgname
MyData.PutInClipboard
End Sub