How to avoid Save Prompt During SendCommand on activex autocad api - python-3.x

I am trying to convert .dwg format to png/bmp.
when I use Plot in AutoCAD for converting dwg to png .
plot_command = "-PLOT yes base1\r\nPublishToWeb PNG.pc3\rSun Hi-Res (1600.00 x 1280.00 Pixels)\rP\rN\rE\rF\rC\rY\r.\rY\rN\rN\rN\r\n& 'D:/autocad_test/see.png'& \r\n"
doc.SendCommand(plot_command)
during this command Save prompt is coming. I need to override this and also save the file using this single command

I would suggest the following:
doc.SendCommand("_.filedia\n0\n_.-plot\n_Y\n\nPublishToWeb PNG.pc3\nSun Hi-Res (1600.00 x 1280.00 Pixels)\n_P\n_N\n_E\n_F\n_C\n_Y\n.\n_Y\n_N\n_N\n_N\nD:/autocad_test/see.png\n_N\n_Y\n_.filedia\n1\n")
Note that this assumes that the file does not already exist (otherwise there would be an additional prompt to consider - you may therefore wish to incorporate additional code to account for this scenario.

Related

Export (save as) jpg using layer name in Photoshop action

is it possible to copy the current active layer name in Photoshop and use it as the file name for a 'Save As' command in a Photoshop action?
Export Layers to Files isn't suitable because I only want to save a single jpg at a particular point in the action, but because the action is recursive I need a way of changing the filename so that the resulting jpg isn't overwritten with each recursion.
Many thanks!
It's possible to get the name of the activeLayer and save it within an variable:
var layerName = app.activeDocument.activeLayer.name;
var destFile = new File ("~/Desktop/" + layerName + ".jpg");
If you want to document.saveAs() you should set the asCopy parameter to true:
app.activeDocument.saveAs (destFile, docExportOptions, true, Extension.LOWERCASE);
This will prevent a name change of the file you're working with.
Instead of document.saveAs() you could use document.exportDocument() in case you want a really small JPEG output.
app.activeDocument.exportDocument (destFile, ExportType.SAVEFORWEB, docExportOptions);
Have you tried : "Export layers to files..." in Files, Script ? You don't tell us which method you are using right now.
This should export each layer with their name + a custom prefix of your choice.
Also, you may want to take a look at the Insert Menu Item that lets you record a set of actions and then does it automatically. If you need something more complex than the first option, this might be your solution.

Output other than .txt

I'm looking to build a simple program that will simply modify existing output files from an other program so I don't have to open the program and enter a bunch of data the long way. This program is very specific to my domain and has an extension named .wcc. However, when I change the extension of one of these output files to .txt, I get half gibberish :
ÿÿ WPointÿÿ WPolygonÿÿ  WQuadrilateralÿÿ  WMemberDataÿÿ
WLoadÿÿ WLStandardMembersÿÿ WLSavedDesignSettingsÿÿ WLSavedFormatSettingsÿÿ  WLSavedViewSettingsÿÿ WLSavedProjectSettingsÿÿ  WLSavedSettingsÿÿ  WLSavedLoadSettingsÿÿ WLSavedDefaultSettingsÿÿ WLineÿÿ WProductÿÿ WBeamDataÿÿ  WColumnDataÿÿ
WJoistDataÿÿ
WWallStudDataÿÿ WSupportingMemberDataÿÿ WSavedAnalysisSettingsÿÿ WSavedGravityDesignSettingsÿÿ WSavedPreferencesSettingsÿÿ WNotchÿÿ WIJoistÿÿ WFloorCWC37 ÀAE LumberS-P-F No.1/No.2 # À# lumwall.cww ÿÿÿÿ1.2.3.1.Mur_1_EX-D ÿÿÿÿÿÿ B Cÿÿ B C €? 4C 4C   Neige #F #F ÈC ÿÿÿ
WLStandardMembersÿÿ "
There are also musical notes and perpendicular signs which I can't copy paste here. I can sorta read the text, but still not enough to make modifications via txt file. What type of file could this be? Is it even possible to do what I'm trying to do? Thanks!
I am surprised that you are trying to open a .wcc file as a text file (it's contents - as you will see - don't lend themselves to being converted to such a file type); however, the attempt to open the file as a .txt file seems to be specific to your domain.
I noticed part of your question is as follows: "What type of file could this be?"
You are right in thinking that the .wcc file is a rather obscure file type - we don't think about that file type a lot (or are not conscious of it existing). A .wcc file is a WinCam 2000 Cache file that allows WinCam 2000 movies to be previewed in the slide browser - these were often generated by older WinCam 2000 screen recording and editing programs.
Again, the file extension is very rare these days (a Google search only returns ~700 results). But, it appears you have a program that is producing the file, which - as you are saying - "is quite specific to your domain". You may be out of luck with regard to opening them for modification purposes.
Supposedly, you can covert .wac files to .wav files, which are much more relevant to today's technology (and definitely alterable from code); however, without knowing the purpose of the file, e.g. what you are trying to do with the file domain-side, I can't say that this will suit your needs.
Also, the above comments are "correct": changing a file extension will not convert the file to the file extension type. Typically, converters - like a simple software - are needed to convert files.

linux - running system command in R and then writing output to a file

I have R code as below. Below code resides in a file called 'iot.R'. I am executing it in Linux.
I want to print content of variable 'fileinformation' to a file mentioned by file=fileConn...
I thought that the 3rd line will solve the issue, but it is not giving the required output :(
fileinformation = system(paste("file", filenames[1]))
#print(fileinformation)
cat(print(fileinformation),"\r\n","\r\n", file=fileConn)
When I run the file, i get below result. It prints to my screen, rather than writing to the file :(
> source('iot.R')
CH7Data_20130401T135010.csv: ASCII text, with CRLF line terminators
[1] 0
--------------------update1
I also tried below command, but didnt get the expected rsult
cat(capture.output(fileinformation),"\r\n","\r\n", file=fileConn)
You need to set the intern argument to TRUE in your call to system. For instance:
fileinformation<-system("file cinzia_2.gif",intern=TRUE)
fileinformation
#[1] "cinzia_2.gif: GIF image data, version 89a, 640 x 640"
Of course I tried a file on my pc. Setting intern to TRUE the return value of system becomes the console output of the command. Then, when you call cat, you don't need to enclose fileinformation into print, but a simple cat(fileinformation,"\r\n","\r\n", file=fileConn) will suffice.
Hi Just a comment as I dont have enough rep to comment in the normal way. but cant you use
write.table
to save the output to a file? It may be easier?

Changing BUNIT in csh for a FITS file

I'm writing code in .csh, and I'm trying to change the bunit header for a FITS file from K (kelvin) to km/s. How can I do that?
I know in Python I would use new_fitsfile.header['BUNIT']='km/s', but that won't work in the current .csh code, and it's not an option to switch it to Python code.
If this is needed only once, call interactively fv or ds9, move to the header, edit the header card and save the result.
For generic batch jobs, one needs some online FITS editor like fmodhead fmodhead, fthedit, or my fedithead
sed "s:BUNIT = 'K ':BUNIT = 'km/s ':g" old.fits >new.fits
and be very careful to count the significant spaces.

Matlab GA plot in nodisplay mode

I'm using the matlab GA and the plot option 'gaplotrange'. But I'm running matlab on a Linux server through a terminal. So when I try to save the gaplot, I either keep getting an empty image (if I use saveas) or an error (if I use print, I get a message saying it is not supported in the current platform).
Is there any other way I could save the plot in the nodisplay mode?
Here is a piece of my code
opts = gaoptimset('PopulationSize', 256, 'EliteCount',1,'CrossoverFraction',0.8, ...
'Generation', 3, 'PenaltyFactor',80,'SelectionFcn',{#selectiontournament,4}, ...
'CrossoverFcn', #crossoverscattered ,'Vectorized','off', 'UseParallel','always',...
'OutputFcns',#pop_output,'MutationFcn',{#mutationuniform,0.002},'StallGenLimit',3,...
'TolFun', 1e-4,'PlotFcns',#gaplotbestf);
f = figure('vis','off');
[x,fval, exitflag, output, population, scores] = ga(#plate_fitness,16,[],[],[],[],vlb,vub,[],opts);
hgsave(f,'matlabga_range','png');
Matlab has a solution for this one posted here
hgsave('filename')
hgsave(h,'filename')
I don't have much experience with the genetic algorithms toolbox, but a quick glance at the docs shows this
To display a plot when calling ga from the command line, set the PlotFcns field of options to be a function handle to the plot function. For example, to display the best fitness plot, set options as follows
options = gaoptimset('PlotFcns', #gaplotbestf);
So if you're not passing 'PlotFcns' with a handle to the plotting function in, it looks like it won't generate the plot based on command line interaction. Add it in and see if it fixes your problem, more details here
Update:
Turns out the problem was that the ga method's plot was creating its own figure, so the save needed to be on the gcf, see the discussion below for more details.

Resources