• This forum is the machine-generated translation of www.cad3d.it/forum1 - the Italian design community. Several terms are not translated correctly.

correction macro solidworks

  • Thread starter Thread starter LineAT
  • Start date Start date

LineAT

Guest
Good morning.
I tried to ask chatgpt to create a macro that copies me the name of the active document in solid works in the notes and this is what he gave me:

option explicit

sub main()

dim swapp as sldworks.sldworks
dim swmodel as sldworks.modeldoc2

set swapp = application.sldworks
set swmodel = swapp.activedoc

if not swmodel is nothing then
dim filename as string
filename = swmodel.getpathname
if len(filename) > 0 then
' copies the file name in the notes
dim dataobj as new msforms.dataobject
dataobj.settext filename
dataobj.putinclipboard
end if
end if

end

It is actually one of the options I give, but they always have the same problem or "types" or "objects" not declared or invalid.

can you correct it or understand what's wrong?
 
update: theia generated me a working code, I bring it back below:

option explicit

sub main()

dim swapp as sldworks.sldworks
dim swmodel as sldworks.modeldoc2

set swapp = application.sldworks
set swmodel = swapp.activedoc

'copy the active piece code in the notes
swapp.sendmsgtouser "code copied in notes"
dim dataobject as object
set dataobject = createobject("new:{1c3b4210-f441-11ce-b9ea-00a006b1a69}")

dim nomefile as string
filename = swmodel.getpathname
filename = left(filename, instrrev(filename, ".") - 1)
filename = right(filename, len(filename) - instrrev(filename, "\"))

dataobject.settext filename
dataobject.putinclipboard

end

You can close.
 

Forum statistics

Threads
44,997
Messages
339,767
Members
4
Latest member
ibt

Members online

No members online now.
Back
Top