Skip to main content
Patriot_1776
22-Sapphire II
December 3, 2018
Solved

itos headache....

  • December 3, 2018
  • 1 reply
  • 3752 views

Ok, this "itos" stuff is giving me a real headache.  I see a bunch of solutions, but I'm not understanding how to implement them, so I'll be specific.  I want to make the line below work and give me 3 decimal places fro all the parameters.  It's completely retarded that you can't simply use the "[.3]" that you can in dwgs.

 

Anyways, here's what I'm trying to do to get the relation to work to make the parameter "DWG_TITLE2" work to fill out the BOM correctly.  I've made it a flexible part, so it'd be nice to have it work parametrically to fill out the BOM.

 

DWG_TITLE2 = itos(A1_SPRING_OD) + " OD" + "," + " " + itos(A1_FREE_LENGTH) + " LONG," + itos(A1_WIRE_DIAMETER) + " WIRE DIAMETER,"

 

Thanks in advance!

 

Best answer by BenLoosli

A little shorter version:

 

if a1_spring_od - floor(a1_spring_od) == 0
   title_1_len = '000'
else
   title_1_len = extract(itos((a1_spring_od-floor(a1_spring_od)+1)*1000),2,3)
endif
title_1_1 = itos(floor(a1_spring_od))+'.'+title_1_len
 
if a1_free_length - floor(a1_free_length) == 0
   title_2_len = '000'
else
   title_2_len = extract(itos((a1_free_length-floor(a1_free_length)+1)*1000),2,3)
endif
title_1_2 = itos(floor(a1_free_length))+'.'+title_2_len
 
if a1_wire_diameter - floor(a1_wire_diameter) == 0
   title_3_len = '000'
else
   title_3_len = extract(itos((a1_wire_diameter-floor(a1_wire_diameter)+1)*1000),2,3)
endif
title_1_3 = itos(floor(a1_wire_diameter))+'.'+title_3_len
 
dwg_title2 = title_1_1+' OD, '+title_1_2+' LONG, '+title_1_3+' WIRE DIAMETER,'

1 reply

21-Topaz II
December 3, 2018

Okay, here's the lengthy solution:

/*
/* Build "DWG_TITLE2" from the pertinent parameters, each with three decimal
/* places of precision.
/*

/* First, the Spring OD

DWG_TITLE2 = ITOS ( floor ( A1_SPRING_OD ) ) + "."
IF A1_SPRING_OD < 1.0
 DWG_TITLE2 = "0."
ENDIF
DWG_TITLE2 = DWG_TITLE2 + EXTRACT ( ITOS ( floor ( 10^3 * ( 1 + A1_SPRING_OD - floor ( A1_SPRING_OD)))),2,3 )
DWG_TITLE2 = DWG_TITLE2 + " OD, "

/* Second, the Free Length

IF A1_FREE_LENGTH < 1.0
 DWG_TITLE2 = DWG_TITLE2 + "0."
ELSE
 DWG_TITLE2 = DWG_TITLE2 + ITOS ( floor ( A1_FREE_LENGTH ) ) + "."
ENDIF
DWG_TITLE2 = DWG_TITLE2 + EXTRACT ( ITOS ( floor ( 10^3 * ( 1 + A1_FREE_LENGTH - floor ( A1_FREE_LENGTH )))),2,3 )
DWG_TITLE2 = DWG_TITLE2 + " LONG, "

/* Third, the Wire Diameter

IF A1_WIRE_DIAMETER < 1.0
 DWG_TITLE2 = DWG_TITLE2 + "0."
ELSE
 DWG_TITLE2 = DWG_TITLE2 + ITOS ( floor ( A1_WIRE_DIAMETER ) ) + "."
ENDIF
DWG_TITLE2 = DWG_TITLE2 + EXTRACT ( ITOS ( floor ( 10^3 * ( 1 + A1_WIRE_DIAMETER - floor ( A1_WIRE_DIAMETER )))),2,3 )
DWG_TITLE2 = DWG_TITLE2 + " WIRE DIAMETER, "

Hope I didn't miss any parentheses there, but that's how I do these horrible things. Quite a lot of stuff for a simple thing, isn't it?

BenLoosli23-Emerald IIIAnswer
23-Emerald III
December 3, 2018

A little shorter version:

 

if a1_spring_od - floor(a1_spring_od) == 0
   title_1_len = '000'
else
   title_1_len = extract(itos((a1_spring_od-floor(a1_spring_od)+1)*1000),2,3)
endif
title_1_1 = itos(floor(a1_spring_od))+'.'+title_1_len
 
if a1_free_length - floor(a1_free_length) == 0
   title_2_len = '000'
else
   title_2_len = extract(itos((a1_free_length-floor(a1_free_length)+1)*1000),2,3)
endif
title_1_2 = itos(floor(a1_free_length))+'.'+title_2_len
 
if a1_wire_diameter - floor(a1_wire_diameter) == 0
   title_3_len = '000'
else
   title_3_len = extract(itos((a1_wire_diameter-floor(a1_wire_diameter)+1)*1000),2,3)
endif
title_1_3 = itos(floor(a1_wire_diameter))+'.'+title_3_len
 
dwg_title2 = title_1_1+' OD, '+title_1_2+' LONG, '+title_1_3+' WIRE DIAMETER,'
Patriot_1776
22-Sapphire II
December 3, 2018

Thanks Ben!  TOTALLY solved it.  Dunno what kind of magic is behind that, but it flat works.  Thanks bro!

 

Me, I can program only simple stuff, that's beyond my comprehension....  🙂