write to file fails

write to file fails

DGRL
Advisor Advisor
866 Views
2 Replies
Message 1 of 3

write to file fails

DGRL
Advisor
Advisor

Found it

 

For some strange reason only 1 variable was messing around

Fixed it 🙂

 

 

 

Dear forum members,

 

I have a lsp that reads out ATT of my templates ( used in Plant 3D 2016)

There are 3 parts ( 2 different templates ) in this script and 2 of them working fine

the 3th one keeps failing

 

This is what I do

 

(setq blk (ssname (ssget "x" (list (cons 0 "INSERT") (cons 2 "Title Block")))0))

 

Then I read out specific ATT's

This is for the first 2 parts

(setq revdate (LM:GetAttributeValue blk "Rev_Date" ))
(setq dwgname (getvar "DWGNAME" )) ;incl extension
(setq tempsize (LM:GetAttributeValue blk "TEMPLATESIZE" ))
(setq strrev (LM:GetAttributeValue blk "REV" ))
(setq status_o (LM:GetAttributeValue blk "STATUS_O" ))
(setq status_t (LM:GetAttributeValue blk "STATUS_T" ))
(setq strtitle (LM:GetAttributeValue blk "TITLE" )) ; needed for DRS
;(setq strname (LM:GetAttributeValue blk "linenumber" ))
(setq dwgprefix (getvar "dwgprefix"))

 

(setq fn (strcat DRSlijst "output.csv")
      fp (open fn "a")
)
(write-line (strcat revdate dlm dwgname dlm tempsize dlm strrev dlm status_o dlm status_t dlm strtitle dlm dwgprefix) fp)
(close fp)

 

This works perfect but now the 3th part

 

(setq blk (ssname (ssget "x" (list (cons 0 "INSERT") (cons 2 "Title Block")))0))
(setq revdate (LM:GetAttributeValue blk "Rev_Date" ))
(setq dwgname (getvar "DWGNAME" )) ;incl extension
(setq tempsize (LM:GetAttributeValue blk "TEMPLATESIZE" )) is different then above
(setq strrev (LM:GetAttributeValue blk "ISO_REV" ))
(setq status_o (LM:GetAttributeValue blk "STATUS_O" ))
(setq status_t (LM:GetAttributeValue blk "STATUS_T" ))
(setq strtitle (LM:GetAttributeValue blk "ISO_TITLE_2" )) is different then above 
;(setq strname (LM:GetAttributeValue blk "linenumber" ))
(setq dwgprefix (getvar "dwgprefix"))

 

Besides the ATT"s its the same as above

 

Now when writing to file it gives me Command: ; error: bad argument type: stringp nil And not even on every dwg but only a few

I use this to write to the file

(write-line (strcat revdate dlm dwgname dlm tempsize dlm strrev dlm status_o dlm status_t dlm strtitle dlm dwgprefix) fp)

 

When Im going to use the following it works perfect

 

(princ revdate fp)
(princ " " fp)
(princ dwgname fp)
(princ " " fp)
(princ tempsize fp)
(princ " " fp)
(princ strrev fp)
(princ " " fp)
(princ status_o fp)
(princ " " fp)
(princ status_t fp)
(princ " " fp)
(princ strtitle fp)
(princ " " fp)
(princ dwgprefix fp)
(princ " " fp)
;(princ strname fp)
;(princ " " fp)
(princ "\n" fp)
(close fp)

 

My question is why is the princ working and the write-line not

 

If you need more info please let me know

 

Best regards

If this was of any help please kudo and/or Accept as Solution
Kind Regards
0 Likes
867 Views
2 Replies
Replies (2)
Message 2 of 3

DannyNL
Advisor
Advisor

Apparently one of the values you are reading is nil because the attribute doesn't exist in the block. Using princ with a nil value is no problem, but write-line expects a string and will throw the error.

 

Be aware that Plant 3D will only create and populate attributes that are actually used and the empty ones will not be created. So if you have created a title block with a Title1 and a Title2 attribute, the inserted block may have none, one or both attributes depending on what values are written.

 

To be sure that an inserted (title) block has all the attributes as defined in the block, you first need to do a attribute sync to make sure all attributes are created in the block instance.

 

So before you do a ssget on your "title block" you should first use this

 

   (if
      (not (member "BATTMAN.ARX" (mapcar 'strcase (arx))))
      (arxload "battman.arx")
   )
   (acet-attsync "Title Block")

Another option would be to create checks on the returned values and if nil set them to "" before writing them to your file.

0 Likes
Message 3 of 3

john.uhden
Mentor
Mentor

At first I thought that maybe your string length exceeded 256 characters and that that was the problem, but I just tested and had no problem writing a line of 264 characters.  So I'll put my money on @DannyNL's response.

Just one thing though... you have no delimiters between each value, so it will look like "oldmacdonaldhadafarmeieio."

which makes me wonder if those farm-raised shrimp eat hay.  Do they conduct a shrimp drive to get them all into a corral?

John F. Uhden

0 Likes