Autocad Diesel IF expression for sheet number tag - autocad

I am trying to automate a sheet tag with a Diesel expression in AutoCad.
This gets me the twelfth character in the drawing name. But as soon as I get to sheet 10 this will say its sheet 0.
$(substr,$(getvar,dwgname),12,1)
Does anyone know a way to get an If statement to see if the eleventh character is a 0 then run the above code else run $(substr,$(getvar,dwgname),11,2)
This is something i have tried.
$(IF,substr,$(getvar,dwgname),11,1)="0"$(substr,$(getvar,dwgname),11,2,substr,$(getvar,dwgname),12,1)
This appears to be similar to excel formulas. Thanks for any help.

The format for the Diesel if statement is:
$(if, expr, dotrue [, dofalse])
If the expr is nonzero, it evaluates and returns dotrue.
You seem to have a lot more going on in your sample. Do the full evaluation (does the 11th character equal 0 in the expr portion and then set your returns, the false portion is optional and can be omitted.

Here is the Diesel expression i got working for auto sheet no. in autocad fields.
$(if,$(substr,$(getvar,dwgname),11,1)"0",$(substr,$(getvar,dwgname),11,2),$(substr,$(getvar,dwgname),12,1))
$(if,$(substr,$(getvar,dwgname),11,1)"0" = Does character 11 = 0
,$(substr,$(getvar,dwgname),11,2) = if no then take character 11 and the next char.
,$(substr,$(getvar,dwgname),12,1)) = if char 11 is = to 0 then take only char 11.
I use two fields in my autocad border. One for the filename without the sheet no and this one for only the sheet number.
Example filename: A150225_S001.dwg
$(substr,$(getvar,dwgname),1, 7) = Use char from position 1 to 7. "A150225"
$(if,$(substr,$(getvar,dwgname),11,1)"0",$(substr,$(getvar,dwgname),11,2),$(substr,$(getvar,dwgname),12,1)) = Use sheet no. at end of filename string. "1"
Hope this helps anyone looking to do something similar.

Related

If results are not >= "Number" then show blank

New to building Crystal Reports and SQL.
I'm trying to write a script to where if results is >= 12.1 then show result else show no results.
Same goes for the <=9.9.
Here is what I have so far:
if {Test.Name} = "xyz" and {TestResults.numresult}>= 12.1 then {TestResults.numresult} else "";
Below is an image showing the same results across the board. I just want the results to show when its <=9.9 or >=12.1.
Hope this make sense.
Your statement returns a number from one branch and a string from the other. It must return the same data type.
One option is to use a True/False expression in a Suppress expression.
Another option is to return a zero in the other branch and use number formatting to suppress if zero (it's a built-in option for numbers).
Another option is to modify your expression so it returns a string from both branches. For example:
if {Test.Name} = "xyz" and {TestResults.numresult}>= 12.1 then ToText({TestResults.numresult}, 1, ",") else "";
The 1 argument requests 1 decimal point. The "," argument requests a comma as thousands separator. You can adjust those to match your number formatting requirements.

Returning Values of Varying Length Between Two Characters with VBS [duplicate]

This question already has an answer here:
vbscript split string with colon delimiter
(1 answer)
Closed 1 year ago.
I am trying to come up with a method for extracting information from a file heading. The overall naming convention of the file heading will remain the same but portions of the heading will vary in character length. Below are two possible examples of such file headings:
012345678-012345-xxxx-yyyyy.txt
012345678-012345-xxx-yyyyyy.txt
Is there a way to extract values from these file headings such that it returns whatever appears between the second and third hyphen? Using the examples above it would return:
xxxx
xxx
Furthermore, is it possible to extract the values between the final hyphen and the period? Using the example above it would return:
yyyyy
yyyyyy
Extracting values is trivial when the character lengths are fixed, but I don't know if it's possible to do a similar extraction when the character lengths vary. I would normally use something like this to extract the information from a fixed-length naming convention but don't know how to adapt it to something where the character lengths change. For example, the snippet below is a function which extract the first nine characters in a file heading (in this case it would extract '012').
Function getthething(foo)
getthething = Mid(foo,1,3)
End Function
Any guidance would be very appreciated. Thank you.
You can do all of this using the Split function. Here's a wrapper function that simplifies things:
Function GetField(p_sText, p_sDelimiter, p_iIndex)
Dim arrFields
arrFields = Split(p_sText, p_sDelimiter)
If UBound(arrFields) >= (p_iIndex - 1) Then
GetField = arrFields(p_iIndex - 1)
Else
GetField = ""
End If
End Function
You can use this function like this:
Dim sFileName
Dim sYs
sFileName = GetField("012345678-012345-xxxx-yyyyy.txt", ".", 1)
sYs = GetField(sFileName, "-", 4)
MsgBox sYs
or simply:
MsgBox GetField(GetField("012345678-012345-xxxx-yyyyy.txt", ".", 1), "-", 4)

remove decimal and leading zeros

Below is some vbscript that populates a field called Lot. At the moment when I run this the Lot field is displaying the ManualLot field as 123456.000000.
Does anyone know how I can change the code below to make 123456.000000 just 0000123456? So it removes the .000000 and starts with 0000 instead.
Function ManualLot_OnAfterChange()
If Backflushing.CodeObject.Quantity < 0 Then
Backflushing.CodeObject.Lot = Backflushing.CodeObject.ManualLot
Else
If Backflushing.CodeObject.Quantity > 0 Then
Backflushing.CodeObject.Lot = 0
End If
End If
End Function
You could use Split() get the value to the left of the decimal, and then use Left() to stick some zeros in front of it.
'how long the number should be
testLength=10
'The number we are changing
test="12345.00000"
'split(test, ".")(0) will get us the values to the left of the decimal
test=LEFT("000000000000", testLength-len(split(test, ".")(0))) & split(test, ".")(0)
msgbox(test)
Backflushing.CodeObject.Lot = RTrim (Backflushing.CodeObject.ManualLot)
Fixed it for me. Thanks for the help though JNevil got me on right track.

Automatically increment filename VideoWriter MATLAB

I have MATLAB set to record three webcams at the same time. I want to capture and save each feed to a file and automatically increment it the file name, it will be replaced by experiment_0001.avi, followed by experiment_0002.avi, etc.
My code looks like this at the moment
set(vid1,'LoggingMode','disk');
set(vid2,'LoggingMode','disk');
avi1 = VideoWriter('X:\ABC\Data Collection\Presentations\Correct\ExperimentA_002.AVI');
avi2 = VideoWriter('X:\ABC\Data Collection\Presentations\Correct\ExperimentB_002.AVI');
set(vid1,'DiskLogger',avi1);
set(vid2,'DiskLogger',avi2);
and I am incrementing the 002 each time.
Any thoughts on how to implement this efficiently?
Thanks.
dont forget matlab has some roots to C programming language. That means things like sprintf will work
so since you are printing out an integer value zero padded to 3 spaces you would need something like this sprintf('%03d',n) then % means there is a value to print that isn't text. 0 means zero pad on the left, 3 means pad to 3 digits, d means the number itself is an integer
just use sprintf in place of a string. the s means String print formatted. so it will output a string. here is an idea of what you might do
set(vid1,'LoggingMode','disk');
set(vid2,'LoggingMode','disk');
for (n=1:2:max_num_captures)
avi1 = VideoWriter(sprintf('X:\ABC\Data Collection\Presentations\Correct\ExperimentA_%03d.AVI',n));
avi2 = VideoWriter(sprintf('X:\ABC\Data Collection\Presentations\Correct\ExperimentB_002.AVI',n));
set(vid1,'DiskLogger',avi1);
set(vid2,'DiskLogger',avi2);
end

ASP Left function issue

I have this code and something odd happening when I'm running it.
I have field number like 101512 up to 101520. I've used LEFT function to get rid of last two digits and keep the 1015. When i runn loop function for the first one it gives me 1015 but for the rest it gives me 101 an it elminates the last digit like this:
d = Split(Request("field"),",")
For i = 1 To UBound(d)
Responce.Write(Left(d(i),4))
Next
Results
1015
101
101
101
...
Does anybody have any idea what is going on?
My guess is that Request("field") may be returning a string like the following:
101520, 101521, 101522
Note the space after each comma. Thus when you apply Left() and print the value to your HTML output you don't notice the space but you only see three digits as the space counted as the first digit
One thing to try to see if this is the case is to change the code to the following:
Left(Trim(d(i)), 4)
That way any spaces around the value are removed before Left() is applied.
Correct way to iterate over "multi value" request item is actually:
For i = 0 To Request("field").Count-1
Response.Write(Request("field").Item(i) & "<br />")
Next
This will iterate the actual values without using split at all..

Resources