Skip to content

Commit

Permalink
Load Text List, Save Text To File
Browse files Browse the repository at this point in the history
  • Loading branch information
Suzie1 committed Dec 27, 2023
1 parent 9200ab4 commit 532739d
Show file tree
Hide file tree
Showing 7 changed files with 904 additions and 12 deletions.
4 changes: 4 additions & 0 deletions Patch_Notes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# 🧩 Comfyroll Custom Nodes - Patch Notes

## v1.52 Dec 27, 2023
- added CR Load Text List
- added CR Save Text To File

## v1.51 Dec 26, 2023
- added CR Thumbnail Template
- added CR_Random Panel Code
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Co-authored by Suzie1 and RockOfFire

Current version: 1.51
Current version: 1.52

# Wiki

Expand Down Expand Up @@ -39,6 +39,7 @@ __📜 List Nodes__
* CR Load Image List Plus (new 23/12/2023)
* CR Float Range List (new 25/12/2023)
* CR Integer Range List (new 25/12/2023)
* CR Load Text List (new 27/12/2023)

__🌟 SDXL__
* CR SDXL Prompt Mix Presets
Expand Down Expand Up @@ -184,6 +185,7 @@ __📦 Other__
* CR Conditioning Mixer
* CR Select Model
* CR Multiline Text (new 24/12/2023)
* CR Save Text To File (new 27/12/2023)

__Deleted Nodes__
* CR Aspect Ratio SDXL replaced by CR SDXL Aspect Ratio
Expand Down
7 changes: 4 additions & 3 deletions animation_nodes/schedules.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def csvoutput(self, output_file_path, file_name, schedule, file_extension):
else:
break

print(f"[Info] CR_Output Schedule To File: Saving to {filepath}")
print(f"[Info] CR Output Schedule To File: Saving to {filepath}")

if file_extension == "csv":
with open(filepath, "w", newline="") as csv_file:
Expand Down Expand Up @@ -265,7 +265,7 @@ def INPUT_TYPES(s):

def csvinput(self, input_file_path, file_name, file_extension):
filepath = input_file_path + "\\" + file_name + "." + file_extension
print(f"CR_Load Schedule From File: Loading {filepath}")
print(f"CR Load Schedule From File: Loading {filepath}")

lists = []

Expand All @@ -285,7 +285,8 @@ def csvinput(self, input_file_path, file_name, file_extension):
second_part = parts[1].strip('"')
lists.append([parts[0], second_part])

print(lists)
#print(lists)

return(lists,str(lists),)

#---------------------------------------------------------------------------------------------------------------------#
Expand Down
20 changes: 13 additions & 7 deletions live_node_mappings.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,22 @@
"CR Integer Multiple": CR_IntegerMultipleOf,
"CR Latent Batch Size": CR_LatentBatchSize,
"CR Seed": CR_Seed,
"CR Prompt Text": CR_PromptText,
"CR Split String": CR_SplitString,
"CR Value": CR_Value,
"CR Conditioning Mixer": CR_ConditioningMixer,
"CR Select Model": CR_SelectModel,
"CR Multiline Text": CR_MultilineText,
### Text Nodes
"CR Prompt Text": CR_PromptText,
"CR Split String": CR_SplitString,
"CR Multiline Text": CR_MultilineText,
"CR Save Text To File": CR_SaveTextToFile,
### List Nodes
"CR Font File List": CR_FontFileList,
"CR Text List": CR_TextList,
"CR Load Image List": CR_LoadImageList,
"CR Load Image List Plus": CR_LoadImageListPlus,
"CR Float Range List": CR_FloatRangeList,
"CR Integer Range List": CR_IntegerRangeList,
"CR Integer Range List": CR_IntegerRangeList,
"CR Load Text List": CR_LoadTextList,
### Aspect Ratio Nodes
"CR SD1.5 Aspect Ratio": CR_AspectRatioSD15,
"CR SDXL Aspect Ratio": CR_SDXLAspectRatio,
Expand Down Expand Up @@ -234,19 +237,22 @@
"CR Integer Multiple": "⚙️ CR Integer Multiple",
"CR Latent Batch Size": "⚙️ CR Latent Batch Size",
"CR Seed": "🌱 CR Seed",
"CR Prompt Text": "📝 CR Prompt Text",
"CR Split String": "⚙️ CR Split String",
"CR Value": "⚙️ CR Value",
"CR Conditioning Mixer": "⚙️ CR Conditioning Mixer",
"CR Select Model": "🔮 CR Select Model",
### Text Nodes
"CR Prompt Text": "⚙️ CR Prompt Text",
"CR Split String": "⚙️ CR Split String",
"CR Save Text To File": "⚙️ CR Save Text To File",
"CR Multiline Text": "⚙️ CR Multiline Text",
### List Nodes
"CR Font File List": "📜 CR Font File List",
"CR Text List": "📜 CR Text List",
"CR Load Image List": "📜 CR Load Image List",
"CR Load Image List Plus": "📜 CR Load Image List Plus",
"CR Float Range List": "📜 CR Float Range List",
"CR Integer Range List": "📜 CR Integer Range List",
"CR Integer Range List": "📜 CR Integer Range List",
"CR Load Value List": "📜 CR Load Value List",
### Aspect Ratio Nodes
"CR SD1.5 Aspect Ratio": "🔳 CR SD1.5 Aspect Ratio",
"CR SDXL Aspect Ratio": "🔳 CR SDXL Aspect Ratio",
Expand Down
105 changes: 104 additions & 1 deletion nodes/nodes_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import folder_paths
import re
import comfy.sd
import csv
from PIL import Image
from pathlib import Path
from ..categories import icons
Expand Down Expand Up @@ -330,6 +331,7 @@ def schedule(self, schedule, end_index):

#---------------------------------------------------------------------------------------------------------------------#
class CR_FloatRangeList:

@classmethod
def INPUT_TYPES(s):
return {"required": {"start": ("FLOAT", {"default": 0.00, "min": -99999.99, "step": -99999.99, "max": 99999.99}),
Expand Down Expand Up @@ -368,6 +370,7 @@ def make_range(self, start, end, step, loops, ping_pong):

#---------------------------------------------------------------------------------------------------------------------#
class CR_IntegerRangeList:

@classmethod
def INPUT_TYPES(s):
return {"required": {"start": ("INT", {"default": 0, "min": -99999, "max": 99999}),
Expand Down Expand Up @@ -402,6 +405,105 @@ def make_range(self, start, end, step, loops, ping_pong):
show_help = "https://github.com/Suzie1/ComfyUI_Comfyroll_CustomNodes/wiki/List-Nodes#cr-list-schedule"

return (range_values, show_help, )


#---------------------------------------------------------------------------------------------------------------------#
class CR_LoadTextList:

@classmethod
def INPUT_TYPES(s):
return {"required": {
"input_file_path": ("STRING", {"multiline": False, "default": ""}),
"file_name": ("STRING", {"multiline": False, "default": ""}),
"file_extension": (["txt", "csv"],),
}
}

RETURN_TYPES = ("STRING", "STRING",)
RETURN_NAMES = ("STRING", "show_help", )
OUTPUT_IS_LIST = (True, False)
FUNCTION = 'load_list'
CATEGORY = icons.get("Comfyroll/List")

def load_list(self, input_file_path, file_name, file_extension):

show_help = "https://github.com/Suzie1/ComfyUI_Comfyroll_CustomNodes/wiki/List-Nodes#cr-load-value-list"

filepath = input_file_path + "\\" + file_name + "." + file_extension
print(f"CR Load Values: Loading {filepath}")

list = []

if file_extension == "csv":
with open(filepath, "r") as csv_file:
for row in csv_file:
list.append(row)

elif file_extension == "txt":
with open(filepath, "r") as txt_file:
for row in txt_file:
list.append(row)
else:
pass

return(list, show_help, )

#---------------------------------------------------------------------------------------------------------------------#
class CR_SaveTextToFile:

@classmethod
def INPUT_TYPES(s):
return {"required": {
"multiline_text": ("STRING", {"multiline": True, "default": ""}),
"output_file_path": ("STRING", {"multiline": False, "default": ""}),
"file_name": ("STRING", {"multiline": False, "default": ""}),
"file_extension": (["txt", "csv"],),
}
}

RETURN_TYPES = ("STRING", )
RETURN_NAMES = ("show_help", )
OUTPUT_NODE= True
FUNCTION = 'save_list'
CATEGORY = icons.get("Comfyroll/Other")

def save_list(self, multiline_text, output_file_path, file_name, file_extension):

show_help = "https://github.com/Suzie1/ComfyUI_Comfyroll_CustomNodes/wiki/List-Nodes#cr-save-text-list"

filepath = output_file_path + "\\" + file_name + "." + file_extension

index = 1

if(output_file_path == "" or file_name == ""):
print(f"[Warning] CR Save Text List. No file details found. No file output.")
return ()

while os.path.exists(filepath):
if os.path.exists(filepath):
filepath = output_file_path + "\\" + file_name + "_" + str(index) + "." + file_extension
index = index + 1
else:
break

print(f"[Info] CR Save Text List: Saving to {filepath}")

if file_extension == "csv":
text_list = []
for i in multiline_text.split("\n"):
text_list.append(i.strip())

with open(filepath, "w", newline="") as csv_file:
csv_writer = csv.writer(csv_file)
# Write each line as a separate row in the CSV file
for line in text_list:
csv_writer.writerow([line])
else:
with open(filepath, "w", newline="") as text_file:
for line in multiline_text:
text_file.write(line)

return (show_help, )

#---------------------------------------------------------------------------------------------------------------------#
# MAPPINGS
Expand All @@ -416,6 +518,7 @@ def make_range(self, start, end, step, loops, ping_pong):
"CR Load Image List Plus": CR_LoadImageListPlus,
"CR List Schedule": CR_ListSchedule,
"CR Float Range List": CR_FloatRangeList,
"CR Integer Range List": CR_IntegerRangeList,
"CR Load Text List": CR_LoadTextList,
"CR Save Text To File": CR_SaveTextToFile,
}
'''
Loading

0 comments on commit 532739d

Please sign in to comment.